Thursday, January 14, 2010

Connect to SQL Server Using Windows Authentication in ASP.NET

Step 1. Configure a Connection String

<connectionStrings>
<add name="MyDbConn1"
connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/>
<add name="MyDbConn2"
connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/>
</connectionStrings>

Step 2. Create a custom service account
  • Create a Windows domain account
  • Run the following Aspnet_regiis.exe command to assign the relevant ASP.NET permissions to the account: aspnet_regiis.exe -ga machineName\userName
  • Use the Local Security Policy tool to grant the Windows account the Deny logon locally user right
  • Use IIS Manager to create an application pool running under the new account's identity and assign the ASP.NET application to the pool.
For more details see: How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0

No comments: