我有一个完美的,工作正常的数据库和网站,并且出于某种原因,我会登录并收到错误:
无法打开数据库" BookDatabase"登录请求。登录失败。 用户登录失败
堆栈跟踪:
[SqlException(0x80131904):无法打开数据库" BookDatabase"登录请求。登录失败。用户登录失败 '参比-L10017 \ acallus&#39 ;.]
System.Data.SqlClient.SqlInternalConnection.OnError(SQLEXCEPTION exception,Boolean breakConnection)+5096342
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()+234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler,SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+2294
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔 enlistOK)+35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout, TimeoutTimer超时,SqlConnection owningObject)+245
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,Boolean redirectedUserInstance, SqlConnection owningObject,SqlConnectionString connectionOptions, TimeoutTimer超时)+703
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(的SqlConnection owningObject,TimeoutTimer超时,SqlConnectionString connectionOptions,String newPassword,Boolean redirectedUserInstance) +195 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity) identity,SqlConnectionString connectionOptions,Object providerInfo, String newPassword,SqlConnection owningObject,Boolean redirectedUserInstance)+232
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options,Object poolGroupProviderInfo,DbConnectionPool池, DbConnection owningConnection)+185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(的DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions选项) +33 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection 拥有对象)+524
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(的DbConnection 拥有对象)+66
System.Data.ProviderBase.DbConnectionPool.GetConnection(的DbConnection 拥有对象)+479
System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection 拥有连接)+108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory)+126
System.Data.SqlClient.SqlConnection.Open()+ 125 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate)+95
System.Web.DataAccess.SqlConnectionHelper.GetConnection(字符串 connectionString,Boolean revertImpersonation)+206
System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(字符串 username,Boolean updateLastLoginActivityDate,Int32& status,String& 密码,Int32& passwordFormat,String& passwordSalt,Int32& failedPasswordAttemptCount,Int32& failedPasswordAnswerAttemptCount, 布尔和放大器; isApproved,DateTime& lastLoginDate,DateTime& lastActivityDate)+827
System.Web.Security.SqlMembershipProvider.CheckPassword(字符串 username,String password,Boolean updateLastLoginActivityDate, Boolean failIfNotApproved,String&盐,Int32& passwordFormat)+105
System.Web.Security.SqlMembershipProvider.ValidateUser(字符串 用户名,字符串密码)+106
System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e)+60
System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e)+129 System.Web.UI.WebControls.Login.AttemptLogin()+ 127 7 System.Web.UI.WebControls.Login.OnBubbleEvent(Object source,EventArgs e)+101 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)+37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)+125
System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+167
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)+10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 5563
我已经尝试了一切我能找到的解决这个问题的方法,并找到了以下内容: - 数据库一次只能连接到SQL Server Management Studio或Visual Web Developer - 我再也无法让它在两个程序中同时运行。 - 即使我将它连接到Visual Web Developer,我仍然无法在我的网站上实际执行任何连接到数据库的操作(我收到上述错误)。
我通过Windows身份验证连接到我的服务器实例,数据库位于我的网站的App_Data文件夹中 - 我最初将其附加到Management Studio。
我的web.config如下:
<configuration>
<system.web>
<authorization>
<allow roles="Administrator"/>
</authorization>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<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="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
</system.web>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\IPT2012;Initial Catalog=BookDatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
我已经尝试了一切。在真正沮丧地撕掉我的头发之前,有人可以对这种情况有所了解。
答案 0 :(得分:0)
在您的连接字符串中添加用户ID和密码属性
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\IPT2012;Initial Catalog=BookDatabase;Integrated Security=True; User ID = userName; Password = yourpassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>