1

I am making a desktop application in C#, Visual Studio 2010 on Windows XP SP2 Professional.

If I run that application directly from the published folder without running setup OR run it from debug folder OR simply debug the application, it does not give this error. But if I run setup from published folder and then run it from start menu, it gives this error:

An attempt to attach an auto-named database for file C:\Documents and Settings\Desi\Local Settings\Apps\2.0\Data\K9KMBYK5.881\EKOOHKP2.0Y1\smas..tion_ddac366ea7cca062_0001.0000_c8a0800c5798ef15\Data\SmasDb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I am publishing application to a folder in 'my documents'.

C:\Documents and Settings\Desi\Local Settings\Apps\2.0\Data\K9KMBYK5.881\EKOOHKP2.0Y1\smas..tion_ddac366ea7cca062_0001.0000_c8a0800c5798ef15\Data\1.0.0.0 (this Data directory has only the user.config file.)

C:\Documents and Settings\Desi\Local Settings\Apps\2.0\LWGCKB30.QZJ\E81QYJON.ZX9\manifests (contains smas..tion_ddac366ea7cca062_0001.0000_none_a42d8ca7a940cae4.cdf-ms smas..tion_ddac366ea7cca062_0001.0000_none_a42d8ca7a940cae4.manifest smas.exe_ddac366ea7cca062_0001.0000_none_3d144d2ce016963b.cdf-ms smas.exe_ddac366ea7cca062_0001.0000_none_3d144d2ce016963b.manifest)

C:\Documents and Settings\Desi\Local Settings\Apps\2.0\LWGCKB30.QZJ\E81QYJON.ZX9\smas.exe_ddac366ea7cca062_0001.0000_none_3d144d2ce016963b (contains SMAS.exe.config, SmasDb.mdf, SmasDb_log.ldf)

C:\Documents and Settings\Desi\Local Settings\Apps\2.0\LWGCKB30.QZJ\E81QYJON.ZX9\smas..tion_ddac366ea7cca062_0001.0000_c8a0800c5798ef15 (this directory has all files including all dlls, SmasDb.mdf and SmasDb_log.ldf, SMAS.exe.config, some .cdf-ms and .manifest files NOT same as above .cdf-ms and .manifest)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SMUsamaShah
  • 7,677
  • 22
  • 88
  • 131

2 Answers2

0

You are using ClickOnce and using a SQL CE database? Did you include the database in the Published application?

Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87
0

Did you verify that the long path (C:\Documents and Settings\USER\Local Settings\Apps\2.0\Data\MP63M1NA.ZG5\BCOVJJWN.C53\smas..tion_ddac366ea7cca062_0001.0000_9c79a710d42895b6\Data\SmasDb.mdf) to see if there actually is a database there?

From the three options in the error message, I would go for: or specified file cannot be opened

You'll have to think about where you want the database to be (on a non-developer computer), and make sure it is copied there.

See the post Working with Databases in Visual Web Developer 2005 Express Edition about the |DataDirectory| syntax.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
H H
  • 263,252
  • 30
  • 330
  • 514
  • This is the problem. Above directory only contains the user.config file. All other files are in other directories. Added more details to question. – SMUsamaShah Aug 13 '10 at 00:13
  • How to make sure that databse is copied to datadirectory? – SMUsamaShah Aug 13 '10 at 00:46
  • I made a really bad design i think. The connectionString, DataSet, and all the classes are in another dll project in the same solution. (i did this because the requirement was to make have a dll instead of doing everything in main project) Now the possible solution is to make sure that the database files are copied to DataDirectory. How to do that? – SMUsamaShah Aug 13 '10 at 01:00
  • 1
    You can change where |DataDir| points to, see http://social.msdn.microsoft.com/forums/en-US/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296/ – H H Aug 13 '10 at 07:30
  • The file is not being copied to DataDirectory. How to copy? – SMUsamaShah Aug 13 '10 at 15:01
  • 1
    Hurrah!!!!! ClickOnce setup is now working. I added the code to copy smasdb.mdf manually near the installation folder (near |DataDirectory|). App is working fine from start menu without error – SMUsamaShah Aug 13 '10 at 17:17