简体   繁体   中英

SQL Server Windows Auth using other Credentials than logged on User

I got this Connection String in C#:

    strg_SQL_Connection = @"Server=Server\Instance; Database=DB;UID=domain\user; Password=password;";

It always tries to Login using the User that is logged on on my development machine which I don't want. How can I fix this?

You cannot use Windows credentials from a connection string. Your process, or at least your thread, must actually impersonate the desired user before establishing the connection. There are many ways you can impersonate, refer to MSDN for details. See WindowsIdentity.Impersonate() and/or Client Impersonation .

A trivial way to achieve impersonation is using runas.exe

You can find the SQL Server Management Studio in the Start Menu, hold down shift , right click on it and choose "Run as different user". Essentially the same as the runas.exe option, maybe quicker to find for a one-off use, but no option to save credentials either.

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