This is very similar to a previous question, but I am looking for an answer that updates it for the latest localDB and Visual Studio 2013. [edit: this also applies to Visual Studio 2015] There also is another question similar to this one but with no answer.
The situation is that I have a WPF application that uses LocalDB. I have a connection string in my app.config with "Data Source=(localdb)\mssqllocaldb", the correct initial catalog and some other stuff. It does not specify the mdf file. Everything works if I build and launch from release/bin or debug/bin.
When I publish using clickOnce on my dev machine, the application gets installed and appears in the start menu. The problem is that when I launch it, an exception is thrown, drilling down the inner exceptions, the complaint appears to be ...
The underlying provider failed on Open.
Cannot attach the file 'C:\Users\myName\AppData...\myContext.mdf'as database myContext
I don't understand what is going on here. I had expected that the installed ClickOnce app would just use the connection string in app.config and then work with the already existing database in (localDB)/mysqllocaldb. Instead, it is trying to attach an mdf file (which, by the way doesn't exist) to my localDB where I already have the database the application uses.
There appears to be NO resources ANYWHERE on how to just get clickonce working when there is a localdb involved. Nor can I infer what the correct behavior should be based on MSDN docs. It certainly isn't behaving as one would reasonably expect.
How do I make ClickOnce deploy an application that uses LocalDB in the following scenarios:
Deploy an application with a specific localDB mdf file, overwriting any existing one with same name.
Deploy an application that uses an already existing localDB mdf file on the target machine (I would build the application to use the correct connectionString or config at runtime).
And here's a long shot... deploy an application that uses some arbitrary logic to determine whether to overwrite any existing localDB mdf OR continue to use the existing localDB mdf.