[英]Server error in '/' application - Login failed for user
We've got an ASP.NET application which connects to our database. 我们有一个连接到数据库的ASP.NET应用程序。 We handle this connection using an XML config file which contains information with how access the database (username, password, etc).
我们使用XML配置文件处理此连接,该文件包含有关如何访问数据库的信息(用户名,密码等)。 However when we try to access certain pages we're greeted with the yellow screen of death and a message saying
Login failed for user xxx
. 但是,当我们尝试访问某些页面时,会看到黄色的死亡屏幕,并显示一条消息,提示
Login failed for user xxx
。
When run locally as localhost this error does not appear. 当以本地主机本地运行时,不会出现此错误。 When we deploy our service to the server this error message appears.
当我们将服务部署到服务器时,会出现此错误消息。 Our connection string looks like this:
我们的连接字符串如下所示:
<add key="DBConnection" value="Data Source=[ServerNameHere];Initial Catalog=[DBNameHere];MultipleActiveResultSets=True;User Id=[usernamehere];Password=[passwordhere];" />
For our SQL Server we've got both SQL Server and Windows Authentication mode enabled. 对于我们的SQL Server,我们同时启用了SQL Server和Windows身份验证模式。 I've checked the login properties for the sa account and changed the "Permission to connect to the database engine" set to "Grant" and the "Login" is set to "Enabled", both of which still present the same issue.
我已经检查了sa帐户的登录属性,并将“连接数据库引擎的权限”设置为“ Grant”,“登录”设置为“ Enabled”,这两个问题仍然存在。 The server and database are on the same machine also.
服务器和数据库也位于同一台计算机上。
These were the most common resolutions to others who had the same issue, is there something else we can try to fix the issue? 对于那些遇到相同问题的人来说,这些是最常见的解决方案,我们还有其他方法可以解决此问题吗?
One final note is that when we get the Loging failed for user xxx
, the xxx
is the name of the machine, so it looks like Domain\\MachineName$
when we get the yellow screen of death. 最后一点要注意的是,当我们获得
Loging failed for user xxx
的登录Loging failed for user xxx
, xxx
是计算机的名称,因此当我们看到黄色的死亡屏幕时,它看起来像Domain\\MachineName$
。
EDIT: The exception being thrown is the following: System.Data.SqlClient.SqlException: Login failed for user 'Domain\\MachineName$'.
编辑:引发以下异常:
System.Data.SqlClient.SqlException: Login failed for user 'Domain\\MachineName$'.
I've disabled "continue on exception" in my Visual Studio but this error is nowhere to be found when debugging the application locally. 我在Visual Studio中禁用了“继续异常”,但是在本地调试应用程序时找不到此错误。
Ok so it turns out the issue was that our IIS Manager which was hosting the service for our web application did not have the correct permission to access the database. 好的,事实证明,问题在于托管Web应用程序服务的IIS管理器没有访问数据库的正确权限。 To resolve the issue it required going into SQL Manager and adding both a login AND user for our app pool...
要解决此问题,需要进入SQL Manager并为我们的应用程序池添加登录名和用户...
Keep Windows Authentication enabled. 保持启用Windows身份验证。 The login name should be IIS APPPOOL\\[NAME OF YOUR SERVICE HOSTED ON IIS]
登录名应为IIS APPPOOL \\ [在IIS上驻留的服务名称]
Click on the Server Roles link on the left of the screen and ensure that public and sysadmin is selected. 单击屏幕左侧的“服务器角色”链接,并确保已选择public和sysadmin。
Now create a user for the db you'd like to access... 现在为您要访问的数据库创建一个用户...
This brings up a new window. 这将打开一个新窗口。 Click on it and then select the login you created previously.
单击它,然后选择您之前创建的登录名。 Ok all the windows.
好的,所有的窗户。
Copy and paste the login name as the username 复制并粘贴登录名作为用户名
On the left select Owned Schemas and ensure db_reader and db_writer are selected 在左侧选择“拥有的架构”,并确保选择了db_reader和db_writer
On the left select Membership and ensure that db_reader and db_writer are selected 在左侧选择“成员资格”,并确保选择了db_reader和db_writer
Click ok to create the user; 单击确定创建用户; your app pool hosting your service should now be able to access the DB
您的托管服务的应用程序池现在应该可以访问数据库了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.