简体   繁体   English

“ /”应用程序中的服务器错误-用户登录失败

[英]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 xxxxxx是计算机的名称,因此当我们看到黄色的死亡屏幕时,它看起来像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并为我们的应用程序池添加登录名和用户...

  • Open SQL Server Management Studio and connect to your target server 打开SQL Server Management Studio并连接到目标服务器
  • Under your server expand the Security folder, right click Login and select New Login... 在服务器下,展开“安全性”文件夹,右键单击“登录”,然后选择“新建登录...”。

在此处输入图片说明

  • 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。

  • Click on the User Mapping link on the left of the screen and select the DB you'd like your web service to be able to reach. 单击屏幕左侧的“用户映射”链接,然后选择您希望Web服务能够访问的数据库。
  • Click on the Status link on the left and ensure that the settings are set to Grant for permission to connect to the DB and Enabled for the login. 单击左侧的“状态”链接,并确保将设置设置为“授予”以授予连接数据库的权限,并设置为“启用”以进行登录。

Now create a user for the db you'd like to access... 现在为您要访问的数据库创建一个用户...

  • Expand your chosen DB and expand the Security folder (not to get confused with the security folder above!). 展开您选择的数据库并展开“安全性”文件夹(不要与上面的安全性文件夹混淆!)。 Right click it and select New User... 右键单击它,然后选择新用户...。

在此处输入图片说明

  • Ensure the user type is SQL user with login (may change depending on how your project is accessing the DB) 确保用户类型是具有登录名的SQL用户(可能会根据您的项目访问数据库的方式而变化)
  • To the left of the Login name box there will be a button with ... on it, click it 在“登录名”框的左侧,将有一个带有...的按钮,单击它

在此处输入图片说明

  • 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM