Search code examples
sql-servervb.netdatabase-connectionwindows-authentication

Connect to MS SQL Server using Windows Authentication of a different user (in VSTO application)


When moving my SQL database from the test location to the production environment I've had to move from SQL server authentication to windows authentication. The server is setup for only "sql" login accounts to be able to access it, rather than the everyday user accounts that exist within the company.

This means that the easiest way to make a database viewing tool like DBeaver work is to "run as" your sql login and use the windows authentication dialogue via right click.

My app is an outlook addin though, and so outlook needs to run as the normal user, otherwise they get the wrong email! Is there any way to set the add-in to always run as a particular windows user, or to get it to "login" as that user when it's loaded?

The connection string to authenticate for the current user is easy enough to find on: https://www.connectionstrings.com/sql-server/


Solution

  • This question is answered under a question about active directory authentication here. Hopefully leaving this under the windows authentication tag here will avoid future confusion.

    The answer is that it's only possible to authenticate against the "current" user, and there's no way to use a different username for different portions of software. The only way to do this is via other authentication methods.