Connecting to DB with both Windows authentication and SQL Server authentication in .NET

Kelum
Jan 18, 2021

--

There can be situations where we have to use both windows authentication connections strings and SQL server authentication connection strings.

Approach Overview

for such situations, we can do an impersonation approach.

Example ConnectionStrings can place like the following

web.config code snippet

This is the Impersonate Class we can use for this

Impersonator.cs

App settings values need set like the following for the Windows User.

So We have to update our source code on the Windows authentication access side like the following, SQL authentication side not require any upgrade.

Now we’ll be able to use both approaches :)

--

--