9

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?

3 Answers 3

15

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.

Sign up to request clarification or add additional context in comments.

2 Comments

But the website uses windows authentication, so the app runs as whoever connects to it. Maybe we need to both authenticate with windows and then impersonate this specific user...
@Kjensen, you can use windows authentication without impersonation, and you should be fine.
1

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

Comments

0

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.

2 Comments

That is how I usually do it. However with this hosting provider, they have asked us to use a specific windows account to connect to the SQL server.
@Kjensen: that is the only way to do this - if you need to use a Windows account other than the one your app is running as, you must create a SQL login - no way around it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.