Sql-server – Cannot open database “MyDatabaseName” requested by the login. The login failed. Login failed for user ‘IIS APPPOOL\MyAppName

asp.netiissql server

I have created a web application. I am using SQL 2012 express as a database. Its working fine when I am running on debug mode. When I deployed that application on local IIS it's throwing an error

Cannot open database "databaseName" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MyApplicationName'.

My connection string is <add name="DefaultConnection" connectionString="Data Source=HAPPY\SQLEXPRESS;uid=sa;password=123;Initial Catalog=dwm;integrated security=sspi;" providerName="System.Data.SqlClient" />

I am able to login with this login detail on my SQL 2012 express. I am attaching a screenshot enter image description here.

Best Answer

You are using SSPI Integrated Security, thus it is trying to use Windows authentication. Try setting to False:

 connectionString="Data Source=HAPPY\SQLEXPRESS;uid=sa;password=123;Initial Catalog=dwm;integrated security=False;" providerName="System.Data.SqlClient" 
Related Topic