Connecting to SQL Server Using Windows Authentication and a Specific Account

I have an ASP.Net application that runs using Windows Authentication. Connecting to SQL Server is usually done by creating an sql server account and using this in the connection string.

However, in this particular very restrictive hosting environment, we were asked to use a specific WINDOWS / Active Directory account to connect to SQL Server.

Please note that these are not user user credentials on the site, we need to connect to the SQL server using - this is one specific Windows / AD account.

How do I configure this in my connection string?

+8
sql-server
source share
3 answers

Use a connection string, for example:

Server=YourServer; Database=YourDatabase; Integrated Security=true; 

Your program should run under the account you need to connect. You can identify your website in IIS by editing AppPool.

+14
source share

Use the Runas parameter to run the program using a specific Window user. The program will connect to the sql server with this user.

+1
source share

If you want to achieve this, you need to:

  • determine SQL Server login for this Windows user
  • grant access to SQL Server to enter your database
  • Define a connection string to use this login in SQL Server (+ password) so that the connection is made with this specific user.

Your connection string will look something like this:

 Server=dbServer;database=theData;User ID=loginname;password=Top$ecret 

If you tell SQL Server to use integrated security, it will always use the current user as the user connecting to the server — you cannot change it.

0
source share

All Articles