Reputation: 81
Is there a way to call an aspx
page from SQL Server? I heard about this but no idea how to call?
In my case I have a SQL Job where I need to call aspx
to execute certain tasks.
Upvotes: 0
Views: 2605
Reputation: 2120
You can directly call a page using
Declare @URL varchar(1000)
Declare @Object as Int;
set @URL='your page URL'
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',@URL,'false'
Exec sp_OAMethod @Object, 'send'
Upvotes: 0
Reputation: 18654
Is there a way to call aspx page from SQL Server?
Yes, but please don't. It requires disabling native SQL Server security, and a bunch of other ugly things.
It's much better to do it the other way around. Have your web page call SQL Server to obtain the data it needs. You can even set that up using Service Broker notifications to you don't have to use polling.
Upvotes: 0
Reputation: 63966
You could do what you need (send an email with attachments) from SQL Server without involving any loading of assemblies into SQL Server.
See this answer here. and the complete documentation of sp_send_dbmail here.
Upvotes: 0
Reputation: 62101
NOT AT ALL?
In my case i have a SQL Job where i need to call aspx to execute certain tasks.
Fired for gross abuse. SQL Server is a database. SQL Server jobs (assuming you mean the jobs) is not a replacement for a decent scheduling system. It should not be used to run things like mail campaigns etc.
Rework your system to adhere to SQL Server as it is intended to use, not by making it look like an application server by pretty much abusing every feature possible.
Upvotes: 3
Reputation: 40546
You could create a .NET assembly that performs the http call and load it in SQL Server so it can be accessed from there.
See this MSDN article about how you can create assemblies in SQL and [this one] that shows how to call .Net functions from such an assembly using T-SQL2.
One downside of this is that (as far as I know) there's no way to parameterize the URL to call (like in a config file). Every time the URL changes, you'll have to redeploy the assembly in SQL.
Upvotes: 1