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

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

问题描述

在调试 Visual Studio 2010 网站时出现以下错误:

I am getting the following error while debugging my visual studio 2010 website:

尝试为文件 C:Users...DesktopDpp2012NewApp_Datadppdatabase.mdf 附加自动命名的数据库失败.存在同名数据库,或无法打开指定文件,或位于 UNC 共享.

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

描述:在执行当前 Web 请求的过程中发生了未处理的异常.请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.Data.SqlClient.SqlException:尝试为文件 C:Users...DesktopDpp2012NewApp_Datadppdatabase.mdf 附加自动命名的数据库失败.存在同名数据库,或无法打开指定文件,或位于 UNC 共享.

Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:Users...DesktopDpp2012NewApp_Datadppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

这是我的 web.config 中的连接字符串:

Here is my connection string from my web.config:

<connectionStrings>
    <add name="ApplicationServices" 
         connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" 
         providerName="System.Data.SqlClient"/>
    <add name="ConnectionString" 
         connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|dppdatabase.mdf;Integrated Security=SSPI" 
         providerName="System.Data.SqlClient"/>
</connectionStrings>

我从我的网站访问它:

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

堆栈跟踪将错误行显示为:

The stacktrace shows the error line as:

 Dim conn As New SqlConnection(connectionString)
 Dim dr As SqlDataReader
 conn.Open() 'This is the error line as per stacktrace

我已经为上述文件夹提供了所需的权限,所以它不会是或指定的文件无法打开"的问题.如果我们查看本论坛所有与同一错误相关的帖子,就可以清楚地发现该错误的严重性.但是,没有一个解决方案可以解决我的问题.我尝试过的一些资源是:

I have given the needed permissions to the above folder so it can not be the " or specified file cannot be opened" issue. If we look at all the posts related to the same error in this forum, clearly the profoundness of this error can be found out. However, none of the solutions solves my issue. Some of the resources which I have tried are:

  1. http://weblogs.asp.net/scottgu/存档/2005/08/25/423703.aspx
  2. http://blogs.msdn.com/b/webdevelopertips/archive/2010/05/06/tip-106-did-you-know-how-to-create-the-aspnetdb-mdf-file.aspx
  3. http://forums.asp.net/t/1033225.aspx

我急切地等待解决方案.

I eagerly await a solution.

推荐答案

我也遇到了这个问题,很痛苦.我配置了我的连接字符串并设法解决了问题.在连接字符串中,我用文件路径替换了 |DataDirectory|dbfilename.mdf 属性的 AttachDbFilename 值.|数据目录|仅当数据库文件在同一项目内的 App_Data 文件夹中时才能使用.

I had this problem also and it was a pain. I configured my connection string and managed to solve the problem. In the connection string I replaced the value |DataDirectory|dbfilename.mdf for AttachDbFilename property, with the path to the file. |DataDirectory| can only be used if the database file is in the App_Data folder inside same project.

因此将 AttachDbFilename 属性更改为 mdf 文件的直接路径,解决了我的问题.

So changing the AttachDbFilename property to the direct path of the mdf file, fixed my issue.

AttachDbFilename=C:MyAppAppDALdb.mdf

我希望这对你有用.

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

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