尝试为文件xxxx附加自动命名数据库失败 [英] An attempt to attach an auto-named database for file xxxx failed

查看:151
本文介绍了尝试为文件xxxx附加自动命名数据库失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地硬盘驱动器上存储了一个数据库文件(FinanceDB.mdf).我可以连接到该文件,但是当我通过C#对它执行查询时,出现以下错误:

I have a database file (FinanceDB.mdf) stored on the local harddrive. I can connect to the file, but when I execute queries to it through C#, I get the following error:

尝试为文件F:\ IT7x01Project \ App_Data \ FinanceDB.mdf附加自动命名的数据库失败.存在具有相同名称的数据库,或者无法打开指定的文件,或者该文件位于UNC共享上.

An attempt to attach an auto-named database for file F:\IT7x01Project\App_Data\FinanceDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

我已经将文件上的每个人的权限都设置为完全访问权限,我认为这可能是问题的一部分,但事实证明并非如此(除非除了设置权限之外,它还有其他用途).

I have set the permissions for everyone on the file to full access which I thought may be part of the problem, but it turns out that its not (unless there is more to it than just setting the permissions).

这是连接字符串:

<add name="FinanceDBConnectionString1" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=F:\IT7x01Project\App_Data\FinanceDB.mdf;Integrated Security=True;" providerName="System.Data.SqlClient"/>

任何帮助,将不胜感激.

Any help with this would be appreciated.

推荐答案

尝试以这种格式创建连接字符串

try to create connection string in this format

<add name="Connec" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=C:\USERS\dL\DESKTOP\DATABASE\MYSHOP.MDF;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>

(或)

尝试将连接字符串中的用户实例"属性设置为true.

Try setting the User Instance property in your connection string to true.

User Instance=True

还要确保再次检查天气,您的数据库服务器已经包含具有相同名称的数据库.

Also just to be sure check again weather your database server already contain a database with the same name.

这篇关于尝试为文件xxxx附加自动命名数据库失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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