c#.net程序中的自动附加错误 [英] Auto-attach error in c#.net programme
本文介绍了c#.net程序中的自动附加错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
项目中的文件夹中有一个SQL数据库文件,连接字符串为:
We have a SQL database file in folder in project and the connection string is :
public string Access_Con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB\Financial.mdf;Integrated Security=True;User Instance=True;";
我们面临以下错误:
and we face following error:
Quote:
尝试为文件附加自动命名的数据库失败。存在具有相同名称的数据库,或者无法打开指定的文件,或者它位于UNC共享上。
An attempt to attach an auto-named database for file failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
但是将连接字符串更改为:
but when change connection string to :
public string Access_Con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|E:\AS-Accounting\Main-proj\accounting\Bisha_accounting\bin\Debug\DB\Financial.mdf ;Integrated Security=True;User Instance=True;";
运行正常。
非常感谢。
that's run correctly.
thanks a lot.
推荐答案
你疯了吗?为什么你把你的数据库放入BIN文件夹?你怎么了,伙计?正确的位置如下:E:\AS-Accounting\Main-proj\accounting\Bisha_accounting\AppData\DB\Financial.mdf
如果你移动你的数据库你的连接字符串将起作用。
| DataDirectory |
指令映射到AppData
应用程序文件夹。拜莎,拜托,不要做蠢事,保持专业!
Are you CRAZY? why did you put your database into the BIN folder??? what's wrong with you, man? The correct location is following:E:\AS-Accounting\Main-proj\accounting\Bisha_accounting\AppData\DB\Financial.mdf
if you move your DB in there your connection string would work.
The|DataDirectory|
directive is mapped to theAppData
application folder. Bisha, please, don't do stupid things, keep professional!
这篇关于c#.net程序中的自动附加错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文