I am running an ASP.Net web application on an IIS server that needs to talk to a SQL database. Below is the connection string that I am using:
<add name="myConn"
connectionString="data source=serverName;initial catalog=dbName;integrated security=True; Trusted_Connection=Yes;"
providerName="System.Data.SqlClient" />
And this is the error I continue to receive:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
I checked a couple other threads with similar errors and was not able to find any solutions. Any ideas would be greatly appreciated.
There are two ways to handle security when connecting to a SQL server database. The configuration of the database server itself is going to tell you which way is even available.
Integrated Security.
This means that you will be executing the queries as the same user that the website is running under. For IIS 7 this is the App Pool user. Sometimes this is configured as Network Service, Local Service, Local System or ApplicationPoolIdentity. If the Database server is not the same as your web server (which it shouldn’t be), then you normally have to use a domain account for the app pool identity to get this to work. That domain account should have the appropriate rights to your database server. An alternative here is to use impersonation. Either way, this is a complicated setup and something you should both research and work with your network administrator on.
SQL Server Security.
This is the traditional username/password that most people are familiar with. You typically need to modify your config to remove the “integrated security=true” part and supply an actual username and password. Note that the database server itself needs to be configured to utilize sql server usernames and that the user should have the appropriate rights to execute your queries against the database.