日期:2014-05-17  浏览次数:20566 次

sql 触发器触发外部程序
xp_cmdshell   我使用过.不成功.不能成功调用此程序。
我简单分析了一下.应该是在mssql 线程空间不允许有其它  进程

我现在还有什么办法能触发外部程序

期待有人帮一下
------最佳解决方案--------------------
CLR....
------其他解决方案--------------------
结帖率:100.00%   都没人顶一下。。真伤心
------其他解决方案--------------------
?這要看是怎樣的操作

xp_cmdshell--調用的語句是SQL Server操作,還是系統操作?

------其他解决方案--------------------
Exec xp_cmdshell 'E:\debug\DBToIM.exe'

这个程序(DBToIM.exe)的作用是登陆openfire  然后发信息

但运行没有结果。

而我双击运行时是可以正常运行的。

通过xp_cmdshell 就失效了
------其他解决方案--------------------
该回复于2010-12-03 11:48:20被版主删除
------其他解决方案--------------------
http://community.kingdee.com/pages/dcyang/blog/archive/2009/12/12/391640.aspx
------其他解决方案--------------------
這是不行的,不可以在觸發器里調用windows程序
樓主可用CLR寫觸發器試試
------其他解决方案--------------------
Exec xp_cmdshell 'Start E:\debug\DBToIM.exe'
是一下这个
------其他解决方案--------------------
楼上的呢

xp_cmdshell 'dir *.exe'


这个在mssql 的线程中是安全的。

而我的程序mssql  不会确认是绝对安全的。会影响 mssql 程序的运行。

所以mssql 执行xp_cmdshell  调用我的程序。应该做了处理。不会正常运行结果


而ls 所讲的帮助文档我看过了。  我确认我也会使用这个命令。你有可以的话可以试试自己写个程序。这个程序 可以开个线程 去做些事情。然后你可以 在触发器中调用这个函数。你看看会不会有一些效果。

谢谢你的帮助。
------其他解决方案--------------------
Exec xp_cmdshell 'start E:\debug\DBToIM.exe'

不可以
------其他解决方案--------------------
to wxf163
 
(小小菜) 

你可以这样试试看。看看自己点击这个程序和  触发器运行这个程序。计算机的反应


        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        [DllImport ( "user32.dll", EntryPoint = "FindWindow", SetLastError = true )]
        private static extern IntPtr FindWindow( string lpClassName, string lpWindowName );
        [DllImport ( "user32.dll", EntryPoint = "FindWindowEx", SetLastError = true )]
        private static extern IntPtr FindWindowEx( IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow );
        [DllImport ( "user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto )]
        private static extern int SendMessage( IntPtr hwnd, uint wMsg, int wParam, int lParam );
        [DllImport ( "user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true )]
        private static extern void SetForegroundWindow( IntPtr hwnd );