我在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)
中這是問題所在。上面的目錄只包含user.config文件。所有其他文件都在其他目錄中。添加更多的細節問題。 – SMUsamaShah 2010-08-13 00:13:09
如何確保databse被複制到datadirectory? – SMUsamaShah 2010-08-13 00:46:31
我覺得我做了一個非常糟糕的設計。 connectionString,DataSet和所有類都在同一解決方案中的另一個dll項目中。 (我這樣做是因爲要求是讓一個dll而不是在主項目中做所有事情)現在可能的解決方案是確保將數據庫文件複製到DataDirectory。怎麼做? – SMUsamaShah 2010-08-13 01:00:49