I spend hours trying multiple combinations to connect my asp.net core site hosted on an IIS Server to a remote SQL Server using just the SQL user and password without exit. This is my connection string in appsettings.json:
"ConnectionStrings": {
"Booking": "Server=SQLServerName;Database=Booking;User Id=XXX;Password=XXX;"
}
Any idea about what I'm doing wrong?
Thank you
SqlException (0x80131904): Login failed for user 'DOMAIN\NAMEOFTHESERVER$'.
This means that the connection string you show is not being used, because this username belongs to NT AUTHORITY\NETWORK SERVICE. So there's another configuration file being used, for example appsettings.development.json, which uses Integrated Security=True, using the application pool's identity.
Change the environment in your web.config to production, so the appsettings.development.json is not used:
<system.webServer>
<aspNetCore ...>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
May be you miss set permissions in IIS if you have set permissions for sql db for a specific user. Hope to help you.
User contributions licensed under CC BY-SA 3.0