How to configure SQL Server to work with ASP.NET MVC with windows authentication?
asp.net, asp.net-mvc, connection-string, sql-server, windows-server-2008
Solution
If your application is running under DefaultAppPool of IIS, it uses the "IIS APPPOOL\DefaultAppPool" acount to access db in integrated mode. So to grant the account in SqlServer:
- open sqlserver instance
- expand security, select "New Login"
- set "IIS APPPOOL\DefaultAppPool" for login name, give db access for the account from "User Mapping" tab.
- click ok to create.
hope this helps.
Problem
This is my connection string: ``` <add name="MyDb" providerName="System.Data.SqlClient" connectionString="Server=localhost;Data Source=.\MSSQLSERVER;Initial Catalog=MyDb;Integrated security=SSPI;" /> ``` It works just fine on my localhost machine, but on my server, after deploying my application, it doesn't want to work, it gives me this error: [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)] When i changed connection string to use account credentials - sa, it connected just fine, so i know exactly that this is problem of bad sql server configuration. So my question is: I have freshly installed sql server instance, how do i configure it so it allows windows authentication for my asp.net mvc application? Edit: Well, after all, i looked at my connection string once again, and removed Data Source=.\MSSQLSERVER. It helped, everything works fine now, thank you guys for helping.