Today, I was working on a webservice which connects to SQL Server Database and inserts some record.
My connection string in the config file is as follows.
Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DataBase;Data Source=(local)
Hosted the service on IIS and tried by calling it. The method was failing by throwing the below exception
login failed for user domain/servername$
Given all the permissions to Network service and one of the user on the DB which the service is connecting but no use.
Copied the code to Console Application and executed it. To my surprise, it worked fine. Then by this, I confirmed that the issue was not in the code or connection string and it was something with IIS.
The problem was the Application Pool Identity. The identity was set to the Built-in Account in the Advanced Settings of App pool, instead change it to one of the user account which has access to Database.
Hope this helps.