我总是收到错误“无法建立与数据库的连接。 如果尚未创建SQL Server数据库,请退出“网站管理”工具,使用aspnet_regsql命令行实用程序创建和配置数据库,然后返回此工具以设置提供程序。“ 我已经创建并配置了数据库,但问题仍然存在。 我在下面分享我的web.config代码
<configuration>
<connectionStrings>
<clear/>
<add name="LocalSqlServer" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial catalog=login;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms"></authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
</configuration>
某处我觉得我在连接字符串中出错了,下面我也在共享我的machine.config连接字符串格式代码
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>