SqlException: Login failed for user 'DOMAIN\MACHINENAME$' for SQL Server with .NET Core 2.1

谁都会走 提交于 2021-02-11 15:51:47

问题


Here is the contents of my connection string. It is an .NET Core 2.1 web application. When I run on my PC, it works fine. When I deploy it to IIS and run it, this error will occur. The detailed error is after the appsetting.

"Testing2012Context": "Server=Server;Database=Testing2012;User ID=User;Password=Pwd;Trusted_Connection=False;MultipleActiveResultSets=true"

Error:

SqlException: Login failed for user 'DOMAIN\MACHINENAME$' for the SQL Server with .NET Core 2.1
...
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, object providerInfo, string newPassword, SecureString newSecurePassword, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling


回答1:


The reason behind the error is iis application pool is running under the local machine account. This account does not have any permission to access your SQL Server.

To resolve this issue you could try the below solutions:

1)open iis manager. Select your application pool.

2)click on advance setting from the action pane.

3)Under Process Model, click on the “Identity” value and select “Custom account” or use network service account.

4)enter your domain user name and password and click ok to apply the changes.

5)after applying changes select the application pool and click on the “Recycle”.

6)restart your site.

or

Grant DOMAIN\SERVERNAME$ user-id read and write to the SQL Server database. The application pool needs to run under the identity of NetworkService. So now the question is how do you add DOMAIN\SERVERNAME$ username as a new login in SQL Server? This may be obvious to many of you, but it tripped a few people including some DBAs here. The key is just to type the DOMAIN\SERVERNAME$ in the Login name: text box without searching it. Click OK button right away. Then you should be able to do the rest to add the roles, etc to the new login.



来源:https://stackoverflow.com/questions/59275810/sqlexception-login-failed-for-user-domain-machinename-for-sql-server-with-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!