简体   繁体   English

跨域运行来自C#应用程序的SQL脚本

[英]Run SQL Scripts from C# application across domains

To run sql script files from my C# application, I referred this. 要从我的C#应用​​程序运行sql脚本文件,我提到了这一点。 http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/43e8bc3a-1132-453b-b950-09427e970f31 http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/43e8bc3a-1132-453b-b950-09427e970f31

it works perfectly when my machine and DB server are in the same domain. 当我的机器和数据库服务器在同一个域中时,它可以正常工作。 my problem now is, i'm executing this console application from a machine (name: X, user id: abc, domain D1). 我现在的问题是,我正在从一台机器上执行这个控制台应用程序(名称:X,用户ID:abc,域D1)。 the SQL server is in another machine (name: Y, domain: D2). SQL服务器在另一台机器上(名称:Y,域:D2)。 I use VPN to connect to machine Y with user id 'abc' and work on SQL in remote desktop. 我使用VPN连接到用户ID为'abc'的机器Y,并在远程桌面上处理SQL。 how can i run sql scripts across domains? 我如何跨域运行SQL脚本? I use this in a custom activity in my TFS build template as the last step to run the scripts in the target database which is in domain D2. 我在我的TFS构建模板中的自定义活动中使用它作为在域D2中的目标数据库中运行脚本的最后一步。

i'm getting this error: "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)" 我收到此错误: “建立与SQL Server的连接时发生网络相关或特定于实例的错误。未找到服务器或无法访问服务器。验证实例名称是否正确以及SQL Server是否配置为允许远程连接。(提供程序:SQL网络接口,错误:26 - 错误定位指定的服务器/实例)“

is it possible to connect to the DB using the admin user ID of machine Y in domain D2? 是否可以使用域D2中的机器Y的管理员用户ID连接到数据库?

问题不在于您位于不同的域,这可能是另一端SQL服务器上的配置问题 - 可能未配置为允许远程SQL连接和/或SQL服务器身份验证 - 或者您只是可以由于某种网络问题而连接到服务器 - 例如,防火墙位于中间 - 一旦确定哪个是问题,您应该能够按照链接的帖子所述运行SQL脚本。

This is not a user credential issue. 这不是用户凭据问题。 You'd be getting a different error. 你会得到一个不同的错误。 It seems as though your client machine can't actually access the server\\instance. 好像您的客户端计算机实际上无法访问server \\ instance。

Try pinging the server. 尝试ping服务器。 If you get a response, then I'd look at a few other things. 如果你得到回复,那么我会看看其他一些事情。 First off, if this is a named instance, then you need to ensure the SQL Server Browser service is started. 首先,如果这是一个命名实例,那么您需要确保启动SQL Server Browser服务。 Also make sure the protocols for the SQL Server service has TCP/IP enabled. 还要确保SQL Server服务的协议已启用TCP / IP。 When you are on the local machine connecting to the instance, you utilize Shared Memory. 当您在连接到实例的本地计算机上时,您使用共享内存。 But remotely it utilizes (or tries to use) TCP/IP. 但远程它利用(或尝试使用)TCP / IP。

Let me know where you're at after those things are checked. 在检查完这些东西之后,让我知道你在哪里。

如果目标SQL Server可以设置为混合身份验证模式,则可以连接到特定的SQL Server UID和PWD帐户而不是网络帐户,而不是作为管理员帐户连接,您的问题将得到解决。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM