How do I configure SQL Server to work with ASP.NET MVC with Windows Authentication?

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 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. server not found or unavailable. Make sure the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - connection string invalid)]

When I changed the connection string to use the credentials - sa it was connected just fine, so I know for sure that this is a bad sql server configuration issue.

So my question is: I just set up an sql server instance, how do I configure it to allow windows authentication for my asp.net mvc application?

Edit: Well, in the end, I looked at the connection string again and removed Data Source =. \ MSSQLSERVER. This helped, now everything works fine, thank you for your help.

+3


source to share


3 answers


If your application is running under IIS DefaultAppPool, it uses "IIS APPPOOL \ DefaultAppPool" to access the db in integrated mode. So, to provide an account in SqlServer:

  • open sqlserver instance
  • expand security, select "New Entry"
  • set "IIS APPPOOL \ DefaultAppPool" for login, give database access for account in "User Mapping" tab.
  • click ok to create.


hope this helps.

+4


source


Take a look at following article on MSDN

which shows how you can change the authentication mode for SQL Server.

You can create SQL Server Management Studio:



  • In the Object Explorer of SQL Server Management Studio, right-click the server and select Properties.
  • On the Security page, under Server Authentication, select the new server authentication mode and click OK.
  • In the SQL Server Management Studio dialog box, click OK to confirm that you want to restart SQL Server.
  • In Object Explorer, right-click your server and select Restart. If SQL Server Agent is running, it must also be restarted.
0


source


First, find out what Windows account your web page is running under. For example, you can print the value:

User.Identity.Name

      

If it is a local account such as "NETWORK SERVICE", you need to change the account. If you are running IIS, account is a property of the application pool.

Once you know the account, you can grant logon rights to that account in SQL Server.

0


source







All Articles