I'm building a WPF application, using EF Code First.
The application seems to work fine while debugging, but when i publish and install it, using ClickOnce, i get this error:
Cannot attach the file [path & filename] as database
I've tried:
checking my connection string using VS Server Explorer
(Cannot attach the file as database / The underlying provider failed on Open)
changing the name of the DB in the connection string
removing tags like
AttachDbFilename
from the connection stringusing sqlcmd to unregister the DB (http://www.eidias.com/Blog/2013/1/7/error-connecting-to-localdb-after-mdf-and-ldf-files-are-deleted)
deleting the localdb instance (http://arabic2000.com/blog/index.php/2013/11/localdb-attach-problem-in-visual-studio-2013/)
deleting the DB using VS' SQL Server Object Explorer
simply omitting the connection string, but then i get a different error:
{"Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path."}
(there is, however, no mention of
|DataDirectory|
in my code, except for a commented out connection string)using
DropCreateDatabaseIfModelChanges
, or evenDropCreateDatabaseAlways
, instead ofCreateDatabaseIfNotExists
On my home PC, i've had to set the app to not look for updates, as i don't have a network to put the installation folder on. When i publish, install and run the app here, i get no errors - but all the app seems to do is run in the background until i kill it's process. The UI never shows.
UPDATE:
Meanwhile, i've deleted the DB using SQL Server Management Studio, and that seems to have helped some.
if i don't use a connection string, i get the
|DataDirectory|
error:Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
if i subsequently run the app in debug mode (which makes EF create the DB), then run (or re-install) the app, i get this error:
no process at the other end of the pipe
if i subsequently delete the DB (that was created during the debug run in the step above) using SQL Server Management Studio, and run the installed app again, again i get the
|DataDirectory|
error.even if i DO use a connection string, specifying an absolute path, i get the
|DataDirectory|
error.if i subsequently run the app in debug mode (which makes EF create the DB), then run (or re-install) the app, i get the
Cannot Attach the file as database
error again.if i subsequently delete the DB (that was created during the debug run in the step above) using SQL Server Management Studio, and run the installed app again, again i get the
|DataDirectory|
error.
UPDATE 2:
I got the app working on my home PC. All it took was... not to use the shortcut ClickOnce added to the Start menu, but run the .exe itself instead.
ClickOnce still doesn't show any notifications once the install is started though, and still fails to launch the app once it's done.
I don't know whether this "fix" will work at work aswell, and won't be able to try it there till tuesday - but i'll keep you posted. I did briefly try it there, and got this error:
Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies
... but i may well have used a dated copy of the .exe, as i was in quite a rush.