0

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

TylerH
  • 20,799
  • 66
  • 75
  • 101
Gouda
  • 27
  • 5
  • But the error is self-explanatory, the login credentials you are using are not valid on the production server. – Dale K Dec 10 '19 at 21:51
  • In addition, unless your User ID is 'DOMAIN\MACHINENAME$' then it looks as if you haven't posted the correct connection string, because it appears to be acting as as integrated security rather than username/password. – Dale K Dec 10 '19 at 22:07
  • That connection string specifies SQL Authentication, and the error comes a failure in Windows Integrated Authentication. So that connection string is not being used when the error occurs. – David Browne - Microsoft Dec 10 '19 at 22:17

1 Answers1

0

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.

enter image description here

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

enter image description here

enter image description here

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.

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26