Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Windows身份验证远程访问的Visual Basic Sql连接字符串_Sql_Sql Server_Vb.net_Vpn - Fatal编程技术网

使用Windows身份验证远程访问的Visual Basic Sql连接字符串

使用Windows身份验证远程访问的Visual Basic Sql连接字符串,sql,sql-server,vb.net,vpn,Sql,Sql Server,Vb.net,Vpn,这有一个很长的背景故事,但总而言之,我正在尝试在我的VB程序中创建一个SQL Server连接,以自动运行一些查询并显示结果。过去,当服务器在我的网络上时,我能够轻松地做到这一点。现在我的公司正转向托管服务器,我遇到了一些问题 使用RUNAS命令时,我可以使用SSMS成功连接到服务器: runas /netonly /user:[network domain]\[username] "C:\Program Files (x86)\Microsoft SQLServer\100\Tools

这有一个很长的背景故事,但总而言之,我正在尝试在我的VB程序中创建一个SQL Server连接,以自动运行一些查询并显示结果。过去,当服务器在我的网络上时,我能够轻松地做到这一点。现在我的公司正转向托管服务器,我遇到了一些问题

使用RUNAS命令时,我可以使用SSMS成功连接到服务器:

    runas /netonly /user:[network domain]\[username] "C:\Program Files (x86)\Microsoft SQLServer\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
但我不知道如何以类似的方式设置VB程序SQL连接字符串

我知道我可以使用
integratedsecurity=SSPI
指定Windows身份验证,但我还需要传递用户名和密码以及网络/域信息

当我尝试执行此操作时,会收到一条“用户登录失败…”消息或“登录来自不受信任的域,无法与Windows身份验证一起使用”,且集成安全性=SSPI

有一些关于Windows模拟的东西,但我一直无法掌握它在这里是如何工作的

如果这是可能的变化需要几乎完全在我这边,因为托管公司是非常…挑剔。。。关于对其环境或设置进行任何更改

我呼吁互联网的智慧来寻求答案

额外事实: SQL Server 2008、Windows 7、Microsoft Visual Studio 2013、Windows窗体程序

对于ASP.NET来说,这是一个很好的解决方案,但我认为代码解决方案也适用于其他平台:

Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(User.Identity, System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

'Insert your code that runs under the security context of the authenticating user here.

impersonationContext.Undo()

在内部,您可以使用通常定义的SSPI运行连接。

User.Identity参数抛出错误。我应该如何将从用户处获得的域\用户名\密码分配给新的标识。@user3473944:检查此项: