简体   繁体   中英

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?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM