2010-08-12 54 views
1

我在C#中創建桌面應用程序,Windows XP SP2 Professional上的Visual Studio 2010。「嘗試附加自動命名的數據庫」錯誤

如果我直接從發佈的文件夾運行該應用程序,而無需運行安裝程序或從調試文件夾運行它或簡單地調試應用程序,它不會給這個錯誤。但是,如果我運行從公佈的文件夾設置,然後從開始菜單中運行它,它給出了這樣的錯誤:在「我的文檔」

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.

我發佈應用程序的文件夾。

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)

回答

0

你驗證長路徑(C:\ Documents和Settings \用戶\本地設置\ APPS \ 2.0 \ DATA \ MP63M1NA.ZG5 \ BCOVJJWN.C53 \ smas..tion_ddac366ea7cca062_0001.0000_9c79a710d42895b6 \ DATA \ SmasDb.mdf )看看那裏是否真的有數據庫?

從錯誤消息的三種選擇,我會去:或指定的文件無法打開

你得想想,你希望數據庫是(在非開發商電腦),並確保它被複制到那裏。

看帖子Working with Databases in Visual Web Developer 2005 Express Edition關於| DataDirectory |句法。

+0

中這是問題所在。上面的目錄只包含user.config文件。所有其他文件都在其他目錄中。添加更多的細節問題。 – SMUsamaShah 2010-08-13 00:13:09

+0

如何確保databse被複制到datadirectory? – SMUsamaShah 2010-08-13 00:46:31

+0

我覺得我做了一個非常糟糕的設計。 connectionString,DataSet和所有類都在同一解決方案中的另一個dll項目中。 (我這樣做是因爲要求是讓一個dll而不是在主項目中做所有事情)現在可能的解決方案是確保將數據庫文件複製到DataDirectory。怎麼做? – SMUsamaShah 2010-08-13 01:00:49

0

您正在使用ClickOnce並使用SQL CE數據庫嗎? 您是否在發佈的應用程序中包含數據庫?

+0

是的,我正在使用ClickOnce和SQL數據庫。並且數據庫包含在已發佈的應用程序 – SMUsamaShah 2010-08-13 00:01:12

相關問題