Sql Server 2005在远程计算机上执行exe或连接到服务器应用程序

时间:2021-03-27 16:28:23

I'm try to figure how to create sql server stored procedure that when a condition is met executes an executable, with command line arguments, on a remote machine within the network. I could write my own little server application to handle the communication sent from the stored procedure for the executable, but I'm not certain if socket programming is a reasonable option with sql server. Any direction would be helpful.

我试图想出如何创建sql server存储过程,当满足条件时,在网络中的远程机器上执行带有命令行参数的可执行文件。我可以编写自己的小服务器应用程序来处理从存储过程发送的可执行文件的通信,但我不确定socket编程是否是sql server的合理选项。任何方向都会有所帮助。

1 个解决方案

#1


You'd need some server-side application anyway, even if that application were SQL Server :)

无论如何,你需要一些服务器端应用程序,即使该应用程序是SQL Server :)

Something like rsh might do - have your local SQL instance invoke xp_cmdshell with an rsh command (or a batch file), connecting to the remote server and executing the command.

像rsh这样的东西 - 让你的本地SQL实例用rsh命令(或批处理文件)调用xp_cmdshell,连接到远程服务器并执行命令。

If you have SQL on the remote machine, it'd be far easier; call a stored procedure on that machine from the local machine, and let that stored procedure do the work (might need fiddling with proxies and "execute as").

如果你在远程机器上有SQL,那就容易多了;从本地机器调用该机器上的存储过程,并让该存储过程完成工作(可能需要摆弄代理并“执行为”)。

A third option would be to create a .NET stored procedure, and do your socket programming or remote invocation from there - it runs in-process, so you get similar same performance and security benefits you'd get from writing it in T-SQL rather than hopping out to a cmdshell with all the mess that entails.

第三种选择是创建.NET存储过程,并从那里执行套接字编程或远程调用 - 它在进程中运行,因此您可以获得与在T-SQL中编写它相同的性能和安全性优势而不是跳到一个带有所有混乱的cmdshell。

#1


You'd need some server-side application anyway, even if that application were SQL Server :)

无论如何,你需要一些服务器端应用程序,即使该应用程序是SQL Server :)

Something like rsh might do - have your local SQL instance invoke xp_cmdshell with an rsh command (or a batch file), connecting to the remote server and executing the command.

像rsh这样的东西 - 让你的本地SQL实例用rsh命令(或批处理文件)调用xp_cmdshell,连接到远程服务器并执行命令。

If you have SQL on the remote machine, it'd be far easier; call a stored procedure on that machine from the local machine, and let that stored procedure do the work (might need fiddling with proxies and "execute as").

如果你在远程机器上有SQL,那就容易多了;从本地机器调用该机器上的存储过程,并让该存储过程完成工作(可能需要摆弄代理并“执行为”)。

A third option would be to create a .NET stored procedure, and do your socket programming or remote invocation from there - it runs in-process, so you get similar same performance and security benefits you'd get from writing it in T-SQL rather than hopping out to a cmdshell with all the mess that entails.

第三种选择是创建.NET存储过程,并从那里执行套接字编程或远程调用 - 它在进程中运行,因此您可以获得与在T-SQL中编写它相同的性能和安全性优势而不是跳到一个带有所有混乱的cmdshell。