1

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:

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.

Community
  • 1
  • 1
Jooj
  • 91
  • 2
  • 9

1 Answers1

0

UPDATE to this answer: i've found a fix:

my trouble seems to have been caused by a faulty connection string:

<add name="4.Data.DienstreisDBContext" connectionString="Data Source=(LocalDb)\v11.0" providerName="System.Data.SqlClient" />

the fault is in the name tag. it should simply say, "DienstreisDBContext" (thereby omitting the name of the folder in which i stored my DBContext class).


I've found a work around:

If i ignore the errors during installation, and use the .exe instead of the Start Menu shortcut ClickOnce generated, my application seems to run fine.

Sadly, this means updating my application won't be as easy as ClickOnce is supposed to make it.

Jooj
  • 91
  • 2
  • 9