Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to call an url through Stored procedure. how can i do it?
Posted

You may not want to hear this advice, but here it goes nevertheless: Don't do this. Stored procedures should handle data and the processing thereof on the SQL Server. Retrieving remote data from a website in a store procedure is calling for all kinds of trouble: Performance, Transaction contention, Non-Determinism etc.. If you absolutely need some external data, fetch it beforehand and pass it along to the SP in the call you are making.

My two cents!

Regards,

Manfred
 
Share this answer
 
Comments
Bhavana P 23-May-12 8:24am    
Thank you Sir ,
for the reply , but its my requirement to call an url through SP , I will get back to you after working on it.
Manfred Rudolf Bihy 24-May-12 5:02am    
Can you tell us about your specific requirement? I would be very interested if this couldn't be solved by a better fitting scenario.

Regards,

Manfred
Bhavana P 24-May-12 5:55am    
Sir, I have tried it using COM objects , I have refered mentioned in the solution below.
Wendelius 23-May-12 16:21pm    
Fully agree!
Try this:
SQL
exec master..xp_cmdshell 'c:\progra~1\intern~1\iexplore.exe www.xyz.com'

Change the path to iexplore.exe as per your machine setup
 
Share this answer
 
v2
This is one of the way I have worked on ,
using COM objects from T-SQL the url is invoked :
First an instance of OLE object is created by using Sp_oacreate then
second method of the web page execution is defined using Sp_oamethod
third the object is destroyed using Sp_oadestroy
It works ...!
 
Share this answer
 
Comments
Prasad_Kulkarni 25-May-12 2:06am    
Don't re-post your answers Princess, use 'Improve solution' widget if you want to add or modify your solution.
Bhavana P 25-May-12 2:27am    
OK Sir, I will implement now onwards.
This is one of the way I have worked on ,
using COM objects from T-SQL the url is invoked :
First an instance of OLE object is created by using Sp_oacreate then
second method of the web page execution is defined using Sp_oamethod
third the object is destroyed using Sp_oadestroy
It works ...!

The @url includes the url to be fetched from a table.
SQL
SET @random=(SELECT CAST(CAST(Rand() * 12000000 AS INT) AS VARCHAR))
                    SET @NAME=@URL + '&randomid=' + @random
					
                    EXEC Sp_oacreate
                      'MSXML2.XMLHTTP',
                      @Object OUT;

                    EXEC Sp_oamethod
                      @Object,
                      'open',
                      NULL,
                      'get',
                      @NAME,
                      'false'

                    EXEC Sp_oamethod
                      @Object,
                      'send'

                    EXEC Sp_oamethod
                      @Object,
                      'responseText',
                      @ResponseText OUTPUT
                     
                    EXEC Sp_oadestroy @Object
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900