我在Visual Studio 2010中构建一个Web站点,并使用存储在ASPNETDB.mdf数据库文件中的成员资格,用户和角色等代码,没有任何问题。现在我试图在运行IIS7.5的网络上部署我的ASP.NET网站即时获取此错误:
An attempt to attach an auto-named database for file .mdf failed. A database with the
same name exists, or specified file cannot be opened, or it is located on UNC share.
以下是我的数据库连接字符串:
<connectionStrings>
<add name="KBDConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\KBD.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
我非常感谢你的帮助
这是我的网站配置(IIS文件夹):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="KBDConnectionString" connectionString="data source=.\SQLEXPRESS;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|KBD.mdf;User
Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<httpHandlers>
<add path="ImgRequest.ashx" verb="*" type="Syncfusion.Web.UI.WebControls.Diagram.NodeRenderHandler,Syncfusion.Diagram.Web, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
<add path="PaletteImgRequest.ashx" verb="*" type="Syncfusion.Web.UI.WebControls.Diagram.ThumbNodeRenderHandler,Syncfusion.Diagram.Web, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
<!--<add path="OverviewImgRequest.ashx" verb="*" type="Syncfusion.Web.UI.WebControls.Diagram.OverviewDocumentRenderHandler,Syncfusion.Diagram.Web, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89"/>-->
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Syncfusion.Tools.Web, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Shared.Web, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Syncfusion.Core, Version=10.404.0.71, Culture=neutral, PublicKeyToken=632609B4D040F6B4" />
<add assembly="Syncfusion.Shared.Base, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Grid.Base, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Tools.Base, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Diagram.Web, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Diagram.Base, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="System.Runtime.Serialization.Formatters.Soap, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Syncfusion.Diagram.Windows, Version=10.402.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Compression.Base, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
<add assembly="Syncfusion.Pdf.Base, Version=10.404.0.71, Culture=neutral, PublicKeyToken=3D67ED1F87D44C89" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership defaultProvider="KBDSqlMembershipProvider">
<providers>
<clear />
<add name="KBDSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="KBDConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="KrallmannBusinessDesigner" />
</providers>
</membership>
<profile defaultProvider="KBDSqlProfileProvider">
<providers>
<clear />
<add name="KBDSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="KBDConnectionString" applicationName="KrallmannBusinessDesigner" />
</providers>
<!--<properties>
<add name="UserName" type="String"/>
<add name="Email" type="String" />
</properties>-->
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<defaultDocument>
<files>
<add value="Account/Login.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
答案 0 :(得分:1)
检查连接字符串。正确的方式(如@Dvjosh提到的MSDN文章中所述):
"AttachDBFilename=|DataDirectory|xxxxxx.mdf;User Instance=true"
您的代码:
AttachDBFilename=|DataDirectory|**\**KBD.mdf
不需要反斜杠。