SQL 服务器 Windows 使用登录用户以外的其他凭据进行身份验证
SQL Server Windows Auth using other Credentials than logged on User
我在 C# 中得到了这个连接字符串:
strg_SQL_Connection = @"Server=Server\Instance; Database=DB;UID=domain\user; Password=password;";
它总是尝试使用我不想要的开发机器上登录的用户登录。我该如何解决这个问题?
您不能使用来自连接字符串的 Windows 凭据。您的进程,或者至少您的线程,必须在建立连接之前实际模拟 所需的用户。您可以通过多种方式进行模拟,有关详细信息,请参阅 MSDN。参见 WindowsIdentity.Impersonate()
and/or Client Impersonation。
实现模拟的一种简单方法是使用 runas.exe
您可以在“开始”菜单中找到 SQL Server Management Studio,按住 shift,右键单击它并选择 "Run as different user"。与 runas.exe 选项基本相同,一次性使用可能更快找到,但也没有保存凭据的选项。
我在 C# 中得到了这个连接字符串:
strg_SQL_Connection = @"Server=Server\Instance; Database=DB;UID=domain\user; Password=password;";
它总是尝试使用我不想要的开发机器上登录的用户登录。我该如何解决这个问题?
您不能使用来自连接字符串的 Windows 凭据。您的进程,或者至少您的线程,必须在建立连接之前实际模拟 所需的用户。您可以通过多种方式进行模拟,有关详细信息,请参阅 MSDN。参见 WindowsIdentity.Impersonate()
and/or Client Impersonation。
实现模拟的一种简单方法是使用 runas.exe
您可以在“开始”菜单中找到 SQL Server Management Studio,按住 shift,右键单击它并选择 "Run as different user"。与 runas.exe 选项基本相同,一次性使用可能更快找到,但也没有保存凭据的选项。