Login failed for user domain servername$

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.
Happy Coding

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s