[英]Calling a URL from a stored procedure in SQL Server?
Just wondering if its possible to call a URL from a stored procedure (eventually adding that procedure to a sql job) As the webpage refreshes my database, it would be excellent if I could automate this process. 只是想知道是否可以从存储过程调用URL(最终将该过程添加到sql作业)当网页刷新我的数据库时,如果我可以自动执行此过程,那将是非常好的。
Edit: 编辑:
I want to be able to request a webpage from a store procedure. 我希望能够通过商店程序请求网页。 On the page load of the desired webpage there is a function that refreshes my database.
在所需网页的页面加载上,有一个刷新我的数据库的功能。 I want it to refresh my database at 4 am every day.
我希望它每天凌晨4点刷新我的数据库。 In order for me not to manually go onto the site at 4am (still sleeping) I need something else to do it for me.
为了让我不要在凌晨4点手动上网(还在睡觉),我需要别的东西给我做。 I thought sql jobs would be excellent, as I can set the time, and the job up.
我认为sql工作会非常好,因为我可以设置时间和工作。 I don't know PowerShell all that well, and wanted to know if I could request a URL, or visit a url using a stored procedure or any other way.
我不太了解PowerShell,并且想知道我是否可以请求URL,或者使用存储过程或任何其他方式访问URL。
I'm pretty sure MS SQL doesn't allow you to do that directly.. obvious security issues. 我很确定MS SQL不允许你直接这样做..明显的安全问题。 However, I think you can get around it by using xp_cmdshell to execute a vbscript file and in that file, create an xmlhttp request to a site.
但是,我认为您可以通过使用xp_cmdshell执行vbscript文件来解决它,并在该文件中创建对站点的xmlhttp请求。
xp_cmdshell command: xp_cmdshell命令:
EXEC master..xp_cmdshell 'c:\<file>.vbs',no_output
VBScript: VBScript中:
call main()
sub main()
Dim xmlHTTP, url
Set xmlHTTP = WScript.CreateObject("Msxml2.XMLHTTP")
url = "<url>"
xmlHTTP.Open "GET", url, False
xmlHTTP.Send ""
end sub
EDIT 编辑
In response to a comment on how to do this asynchronously. 回应关于如何异步执行此操作的注释。
xp_cmdshell command: xp_cmdshell命令:
EXEC master..xp_cmdshell 'c:\caller.vbs',no_output
VBScript for caller: 调用者的VBScript:
call main()
sub main()
Dim scmd
Set scmd = "c:\windows\system32\cscript.exe //nologo c:\<originalVBS>.vbs"
createobject("wscript.shell").run scmd,0,false
end sub
@newurl is url you want to hit @response is response you received @newurl是你要点击的网址@response是你收到的回复
EXEC Sp_oacreate 'MSXML2.XMLHTTP',@obj OUT;
EXEC Sp_oamethod @obj,'open',NULL,'get',@newurl,'false'
EXEC Sp_oamethod @obj,'send'
EXEC Sp_oamethod @obj,'responseText',@response OUTPUT
EXEC Sp_oadestroy @obj
You can do it with Task Scheduler (part of Windows). 您可以使用任务计划程序(Windows的一部分)执行此操作。 Just create a scheduled task that opens Internet Explorer and browses to the page:
只需创建一个打开Internet Explorer并浏览到该页面的计划任务:
"C:\Program Files\Internet Explorer\iexplore.exe" "http://yoursite.com/yourpage.aspx"
Or for 64-bit Windows: 或者对于64位Windows:
"C:\Program Files (x86)\Internet Explorer\iexplore.exe" "http://yoursite.com/yourpage.aspx"
Alternatively, create a job using SQL Server Agent, and create a single step of type "Operating System (CmdExec)" with the above command. 或者,使用SQL Server代理创建作业,并使用上述命令创建“操作系统(CmdExec)”类型的单个步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.