gpt4 book ai didi

asp.net - 尝试为文件…database1.mdf附加自动命名的数据库失败

转载 作者:行者123 更新时间:2023-12-03 10:12:00 28 4
gpt4 key购买 nike

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

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

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.

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



这是来自 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

stacktrace将错误行显示为:
 Dim conn As New SqlConnection(connectionString)
Dim dr As SqlDataReader
conn.Open() 'This is the error line as per stacktrace

我已将所需的权限授予上述文件夹,因此它不会是“或无法打开指定文件”的问题。如果我们查看此论坛中与同一错误相关的所有帖子,则可以清楚地发现此错误的深刻性。但是,没有一种解决方案可以解决我的问题。
我尝试过的一些资源是:
  • http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx
  • http://blogs.msdn.com/b/webdevelopertips/archive/2010/05/06/tip-106-did-you-know-how-to-create-the-aspnetdb-mdf-file.aspx
  • http://forums.asp.net/t/1033225.aspx

  • 我热切等待解决方案。

    最佳答案

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

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

    AttachDbFilename = C:\ MyApp \ App \ DAL \ db.mdf

    希望这对您有用。

    关于asp.net - 尝试为文件…database1.mdf附加自动命名的数据库失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12566036/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com