我在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