Reputation: 10068
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.
Upvotes: 3
Views: 5299
Reputation: 5469
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:
hope this helps.
Upvotes: 6
Reputation: 238078
First figure out under which Windows account your web page is running. You could for example print the value of:
User.Identity.Name
If it's a local-only account like "NETWORK SERVICE", you've got to change the account. If you're running in IIS the account is a property of the application pool.
Once you know the account, you can grant that account login rights in SQL Server.
Upvotes: 0
Reputation: 1038720
Take a look at the following article on MSDN
which illustrates how you could change the authentication mode for SQL Server.
You could SQL Server management studio:
- In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties.
- On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
- In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server.
- In Object Explorer, right-click your server, and then click Restart. If SQL Server Agent is running, it must also be restarted.
Upvotes: 0