Loading ...

How to use Windows Authentication to access SQL Server | CodeAsp.Net

How to use Windows Authentication to access SQL Server

0 (0votes)

While using Windows authentication to access SQL Server in your .NET applications, there are a few important points to consider. First you need to decide if the SQL Server is in the same machine or in a different machine in the network. If the SQL Server is in the same domain or on the same machine as the web server, then you can access it easily by setting the right parameters in the connection string property:

The following shows a typical connection string configured for Windows integrated security:

data source=servername;initial catalog=DB_Name;persist security info=False; Trusted_Connection=Yes.

Note: instead of


You can also use:

Integrated Security=SSPI;

Both are equivalent.

You will also need to use these settings in web.config to turn on the impersonation:

<authentication mode="Windows" />
<identity impersonate="true"/>

You can learn more about impersonation here: http://www.codeasp.net/blogs/vivek_iit/microsoft.net/104/impersonation-in-asp-net

But if you have your SQL Server in a different Windows domain, then you will need to not only use impersonation, but also delegation. Delegation is used to impersonate across the network as impersonation works within the same local machine. For more on delegation, refer this link: http://msdn.microsoft.com/en-us/library/ms998355.aspx


Comments (no comments yet)

Top Posts