Re: [SQL ] SQL Server 2008 R2 執行外部網址
※ 引述《TeemingVoid (TeemingVoid)》之銘言:
: 有兩個方案提供給您參考 --
: 甲案,在 Trigger 以 xp_cmdShell 跑 WSH,然後透過 WSH 叫用 PHP。詳細作法如下:
: 1. 在(例如) c:\temp 建立一個 ShellRun.vbs 程式檔案。(存檔時,編碼請用 Ansi)
: 程式內容:
: Set Shell = WScript.CreateObject("WScript.Shell")
: Shell.Run WScript.Arguments(0)
: 2. 在你的 Trigger 叫用 ShellRun.vbs,例如這樣:
: xp_cmdshell 'dir c:\ > c:\temp\report.txt'
: xp_cmdshell 'c:\temp\ShellRun.vbs "http://www.udn.com"'
: 乙案,不使用 xm_cmdShell,透過 OLE Automation 向 Web Server 發出 request。i.e.
: sp_configure 'show advanced options', 1;
: GO
: RECONFIGURE;
: GO
: sp_configure 'Ole Automation Procedures', 1;
: GO
: RECONFIGURE;
: GO
: Declare @Object as Int
: Declare @ResponseText as Varchar(8000)
: Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
: Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://www.udn.com', 'false'
: Exec sp_OAMethod @Object, 'send'
: Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
: Select @ResponseText
: Exec sp_OADestroy @Object
: GO
感謝大大的幫忙~! 在下使用方案一,確實有達到需求~真的非常感謝
但有個疑問是會不會有 deadlock 的情況出現呢?
我的 trigger 做法是將 SQL 執行 DML 後被修改的資料(delete 時是修改前資料)
做成一份 RAW XML 丟進 dbo.Log 資料表裡
之後在執行 xp_cmdshell 去執行我的 php,將 dbo.Log 資料取出
並組成字串透過 WebService 送到另一端 DB 去
原始作法是使用 xp_cmdshell 執行 php.exe,卻不幸發生 deadlock 的狀況
雖然使用 ShellRun.vbs 解決了 deadlock 的問題
但往後會不會在資料量大與頻繁時又發生 deadlock 的情況呢?
望大大能替資質愚笨的在下解答,感謝大大的大恩大德。 :)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.44.121
討論串 (同標題文章)