简体   繁体   English

使用Windows身份验证从非域计算机访问SQL Server 2005

[英]Access to SQL Server 2005 from a non-domain machine using Windows authentication

I have a Windows domain within which a machine is running SQL Server 2005 and which is configured to support only Windows authentication. 我有一个Windows域,其中一台机器运行SQL Server 2005,并配置为仅支持Windows身份验证。 I would like to run a C# client application on a machine on the same network, but which is NOT on the domain, and access a database on the SQL Server 2005 instance. 我想在同一网络上的计算机上运行C#客户端应用程序,但不在域上,并访问SQL Server 2005实例上的数据库。

I thought that it would be a simple matter of doing something like this: 我认为做这样的事情会很简单:

string connectionString = "Data Source=server;Initial Catalog=database;User Id=domain\user;Password=password";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();

However, this fails: the client-side error is: 但是,这失败了:客户端错误是:

System.Data.SqlClient.SqlException: Login failed for user 'domain\\user\u0026#39; and the server-side error is: Error 18456, Severity 14, State 5 System.Data.SqlClient.SqlException:用户'domain \\ user'登录失败,服务器端错误为:错误18456,严重级别14,状态5

I have tried various things including setting integrated security to true and false, and \\ instead of \\ in the User Id, but without success. 我尝试了各种各样的事情,包括将集成安全性设置为true和false,以及\\而不是用户ID中的\\,但没有成功。

In general, I know that it possible to connect to the SQL Server 2005 instance from a non-domain machine (for example, I am working with a Linux-based application which happily does this), but I don't seem to be able to work out how to do it from a Windows machine. 一般来说,我知道可以从非域计算机连接到SQL Server 2005实例(例如,我正在使用基于Linux的应用程序,很高兴这样做),但我似乎无法找出如何从Windows机器上做到这一点。

With Management Studio when connecting to a server on another domain via Windows Authentication you need to use the "runas" Facility when starting the application. 使用Management Studio通过Windows身份验证连接到另一个域上的服务器时,您需要在启动应用程序时使用“runas”工具。

 runas /user:OTHERDOMAIN\OTHERUSERNAME  /netonly 
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

Maybe you could try an analogous thing when starting your application? 也许你可以在启动应用程序时尝试类似的东西?

(Per Martin Smith's answer) I use RUNAS /NETONLY all the time to run SSMS and the BI dev studio and Visual Studio IDE and other 3rd party applications against a server on a domain we do not authenticate against. (根据Martin Smith的回答)我一直使用RUNAS / NETONLY来运行SSMS和BI开发工作室以及Visual Studio IDE和其他第三方应用程序,对抗我们未对其进行身份验证的域上的服务器。 I'm not sure why you can't do this - you must somehow have an account on that domain which works with SQL Server if you are using integrated security. 我不确定为什么你不能这样做 - 如果你使用集成安全性,你必须以某种方式在该域上拥有一个适用于SQL Server的帐户。

In addition, I modified one of my main C# programs to use CreateProcessWithLogonW with LOGON_NETCREDENTIALS_ONLY ( How to build RUNAS /NETONLY functionality into a (C#/.NET/WinForms) program? ) so that it prompts for username and password and then re-launches itself. 另外,我修改了一个主要的C#程序,使用带有LOGON_NETCREDENTIALS_ONLY的CreateProcessWithLogonW( 如何在(C#/ .NET / WinForms)程序中构建RUNAS / NETONLY功能? ),以便提示输入用户名和密码,然后重新启动本身。

Using the same API, I also made a version of RUNAS /NETONLY which will accept a password on the command-line, since RUNAS will NOT allow a password on the command-line. 使用相同的API,我还制作了一个RUNAS / NETONLY版本,它将在命令行上接受密码,因为RUNAS不允许在命令行上输入密码。 Obviously, this is an inherent security risk, and I don't use it frequently. 显然,这是一个固有的安全风险,我不经常使用它。

As a matter of completeness, there is also this great shell extension: http://technet.microsoft.com/en-us/sysinternals/cc300361.aspx - the regular Run As Shell extension doesn't have the ability to do the equivalent of /NETONLY. 作为完整性问题,还有一个很棒的shell扩展: http//technet.microsoft.com/en-us/sysinternals/cc300361.aspx - 常规的Run As Shell扩展无法做同等的/ NETONLY。

可以在每台计算机上使用相同的用户名和密码创建本地用户创建这些用户后,让SQL Server服务器上的用户访问SQL Server,在另一台计算机上,您的应用程序必须以新创建的方式运行用户,如果是Web应用程序,只需更改应用程序池设置。

Did you try connecting with machineName\\UserName ? 您是否尝试使用machineName \\ UserName进行连接? I'd also imagine that such a user should be created in the SQL database well - correct? 我还想象应该在SQL数据库中创建这样的用户 - 对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从非域计算机连接到域SQL Server 2005 - Connect to domain SQL Server 2005 from non-domain machine Windows Forms 来自非域添加机器的模拟 - Windows Forms Impersonation from a non-Domain added machine 如何将SQL Server 2005从Windows身份验证更改为SQL身份验证? - How to change SQL Server 2005 from Windows Authentication to SQL Authentication? 非域Windows环境中的C#程序化远程文件夹/文件身份验证 - C# Programmatic Remote Folder / File Authentication In Non-Domain Windows Environment 在非域计算机上使用域控制器以编程方式同步时间 - programmatically sync time on non-domain machine with domain controller C#ActiveDirectory - 如何从已加入域的计算机远程添加本地用户帐户到非域计算机 - C# ActiveDirectory - How do I add a local user account remotely from a domain-joined machine to a non-domain machine 无法在非域上访问服务Windows 7自托管WCF应用程序 - Can't access service Windows 7 self-hosted WCF app on a non-domain 如何列出非域计算机上运行代码的域? - How to list domains running code from a non-domain computer? 在非域帐户上使用带有服务帐户凭据的Google API - Using Google API With Service Account Credentials on a non-domain account 使用Windows身份验证连接到不同域上的SQL Server - Connecting to SQL Server on different domain using Windows Authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM