Kjensen
Kjensen

Reputation: 12384

Connect to SQL Server using windows authentication and specific account

I have an ASP.Net app, that runs using windows authentication. The connection to the SQL Server is usually done by creating a sql server account and using that in the connection string.

However, in this specific very restrictive hosting environment, we have been asked to use a specific WINDOWS/active directory account to connect to the SQL Server.

Please note it is not the windows credentials of the user of the website, we need to connect to the SQL server with - it is one specific windows/AD account.

How do I configure that in my connection-string?

Upvotes: 8

Views: 30096

Answers (3)

Snike
Snike

Reputation: 19

Use the Runas option to start the program with the specific Window User. The program will connect to the sql server with this user.

Upvotes: 1

marc_s
marc_s

Reputation: 755287

If you want to achieve this, you need to:

  • define a SQL Server login for that Windows user
  • grant that SQL Server Login access to your database
  • define your connection string to use that SQL Server login (+password) so that the connection is made with that particular user

Your connection string would be something like:

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

If you tell SQL Server to use integrated security, it will always use the currently logged on user as the one who connects to the server - you cannot change that.

Upvotes: 0

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 121037

Use a connectionstring like this:

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

Your program has to run under the account that you need to connect as. You can set the identity of your website in IIS by editing the AppPool.

Upvotes: 14

Related Questions