SQL 无法打开登录请求的数据库“ASPNETDB”。登录失败。用户 'Philip-Desktop\Philip' 登录失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4882926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:10:52  来源:igfitidea点击:

Cannot open database "ASPNETDB" requested by the login. The login failed. Login failed for user 'Philip-Desktop\Philip'

asp.netsqlsecuritylogin

提问by Philip906

I'm been struggling to find an answer to this problem for hours now...

几个小时以来,我一直在努力寻找这个问题的答案......

I use to not get this error while accessing the ASPNETDB database, but unfortunately I don't know what I changed. The error comes up when I try to access a file called Admin.aspx I have in a folder called Admin. I had restrictions set on this folder using the Web Site Administration Tool, but when the error came up I took them all of them off to see what the problem was and I still get the error?? The Admin.aspx file is the only one that gets the error..

我过去在访问 ASPNETDB 数据库时不会收到此错误,但不幸的是我不知道我更改了什么。当我尝试访问名为 Admin 的文件夹中名为 Admin.aspx 的文件时出现错误。我使用网站管理工具对此文件夹设置了限制,但是当出现错误时,我将它们全部关闭以查看问题出在哪里,但我仍然收到错误?Admin.aspx 文件是唯一出现错误的文件。

My connection string in web.config is:

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

<add name="WIJLConnectionString1" connectionString="Data Source=localhost;Integrated Security=SSPI; Initial Catalog=ASPNETDB" providerName="System.Data.SqlClient" />

Here is the error:

这是错误:

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "ASPNETDB" requested by the login. The login failed. Login failed for user 'Philip-Desktop\Philip'.

[SqlException (0x80131904): Cannot open database "ASPNETDB" requested by the login. The login failed. Login failed for user 'Philip-Desktop\Philip'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, 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 pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.SqlClient.SqlConnection.Open() +125 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1618
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

异常详细信息:System.Data.SqlClient.SqlException:无法打开登录请求的数据库“ASPNETDB”。登录失败。用户 'Philip-Desktop\Philip' 登录失败。

[SqlException (0x80131904): 无法打开登录请求的数据库“ASPNETDB”。登录失败。用户 'Philip-Desktop\Philip' 登录失败。]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,Boolean breakConnection) +5009598 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 System.Data.SqlClient。 TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, BooleanConnection redirectedUserStringInstance, BooleanConnection redirectedUserStringInstance, connectionOptions, TimeoutTimer timeout) +239
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, 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 pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest (DbConnection 拥有对象)+66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection externalConnection, DbConnectionFactory connectionFactory) +126
System. Data.SqlClient.SqlConnection.Open() +125 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand 命令, CommandBehavior 行为) +123
System.Data. Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand 命令, CommandBehavior 行为) +319
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1618
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System. Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control .EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI .Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

Someone please help!! I'm desperate at this point

有人请帮忙!!此刻我很绝望

回答by marc_s

The error message is as clear as it can be:

错误消息非常清楚:

Cannot open database "ASPNETDB" requested by the login. The login failed. Login failed for user 'Philip-Desktop\Philip'

无法打开登录请求的数据库“ASPNETDB”。登录失败。用户 'Philip-Desktop\Philip' 登录失败

That Windows user isn't allowed to connect to that database and use it.

不允许该 Windows 用户连接到该数据库并使用它。

Check to make sure:

检查以确保:

  • that you have the proper server name in your connection string. Is it really localhost? Or did you perhaps install SQL Server Express and it ended up being (local)\SQLExpressinstead??

  • that the serveryou're connecting to has a login for Philip-Desktop\Philip(check in Object Explorer -> (your server) -> Security -> Logins)

  • that the databaseASPNETDB has a user based on that login so that you can use that database (check in Object Explorer -> (your server) -> Databases -> (your database) -> Security -> Users)

  • that your admin.aspxpage is truly referencing that connection string you've given (WIJLConnectionString1). Is there by any chance a separate web.configin your Adminfolder that e.g. has a different connection string, and the admin.aspxpage references that connection string instead??

  • 您的连接字符串中有正确的服务器名称。真的localhost吗?或者您是否安装了 SQL Server Express 而结果却是这样(local)\SQLExpress??

  • 您要连接的服务器具有登录名Philip-Desktop\Philip(签入Object Explorer -> (your server) -> Security -> Logins

  • 数据库ASPNETDB具有基于该登录,这样就可以使用该数据库(在检查用户Object Explorer -> (your server) -> Databases -> (your database) -> Security -> Users

  • 您的admin.aspx页面真正引用了您提供的连接字符串 ( WIJLConnectionString1)。web.config您的Admin文件夹中是否有一个单独的文件,例如具有不同的连接字符串,而admin.aspx页面则引用该连接字符串?

回答by Philip906

Thanks for the response I figured out what was wrong.

感谢您的回复,我发现出了什么问题。

Apparently all my SqlDataSource connection strings, inside of the Admin.aspx, had changed from using the connection string that pointed at the correct database (WIJL), to the connection string WIJLConnectionString1 which pointed at the ASPNETDB database. All I had to do was just change the connections strings back

显然,Admin.aspx 中的所有 SqlDataSource 连接字符串都已从使用指向正确数据库 (WIJL) 的连接字符串更改为指向 ASPNETDB 数据库的连接字符串 WIJLConnectionString1。我所要做的就是将连接字符串改回来