为桌面应用程序编写动态连接字符串(C#,SQL SERVER 2005) [英] To write dynamic connection string for desktop application (C# ,SQL SERVER 2005)

查看:59
本文介绍了为桌面应用程序编写动态连接字符串(C#,SQL SERVER 2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在连接到本地SQL Server Express实例时,我已使用附加了位于数据目录中的数据库文件.代码为
conn =新的SqlConnection();
conn.ConnectionString =数据源=.\\ SQLEXPRESS; AttachDbFilename = | DataDirectory | \\ carRent.mdf;集成安全性= True;用户实例= True";
返回conn;
但我收到错误消息:

无法打开物理文件"D:\ CarRent Completed \ CarRent \ bin \ Debug \ carRent.mdf".操作系统错误32:"32(该进程无法访问该文件,因为它正在被另一个进程使用.)".
尝试为文件D:\ CarRent Completed \ CarRent \ bin \ Debug \ carRent.mdf附加自动命名的数据库失败.存在具有相同名称的数据库,或者无法打开指定的文件,或者该数据库位于UNC共享上.
如何解决此错误?感谢您的时间和考虑.

I have used Attach a database file, located in the data directory, on connect to a local SQL Server Express instance.code is
conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\carRent.mdf;Integrated Security=True;User Instance=True";
return conn;
But I get error :

Unable to open the physical file "D:\CarRent Completed\CarRent\bin\Debug\carRent.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
An attempt to attach an auto-named database for file D:\CarRent Completed\CarRent\bin\Debug\carRent.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
how to solve this error?Thanks for your time and consideration.

推荐答案

检查此链接

http://connectionstrings.com/ [ ^ ]

希望对您有帮助
check this link

http://connectionstrings.com/[^]

Hope this will help you


这篇关于为桌面应用程序编写动态连接字符串(C#,SQL SERVER 2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆