create procedure [dbo].[pr_SendSmsSQL] @MobileNo varchar(12), @smstext as varchar(300), @sResponse varchar(1000) OUT as BEGIN Declare @iReq int,@hr int Declare @sUrl as varchar(500) DECLARE @errorSource VARCHAR(8000) DECLARE @errorDescription VARCHAR(8000) -- Create Object for XMLHTTP EXEC @hr = sp_OACreate 'Microsoft.XMLHTTP', @iReq OUT print @hr if @hr <> 0 Raiserror('sp_OACreate Microsoft.XMLHTTP FAILED!', 16, 1) set @sUrl='http://api.clickatell.com/http/sendmsg?user=devendar&password=xxxxxxxxx&api_id=xxxxxxxx&to=#MobNo#&text=#Msg#' set @sUrl=REPLACE(@sUrl,'#MobNo#',@MobileNo) set @sUrl=REPLACE(@sUrl,'#Msg#',@smstext) print @sUrl -- sms code start EXEC @hr = sp_OAMethod @iReq, 'Open', NULL, 'GET', @sUrl, true print @hr if @hr <> 0 Raiserror('sp_OAMethod Open FAILED!', 16, 1) EXEC @hr = sp_OAMethod @iReq, 'send' select @iReq print @hr if @hr <> 0 Begin EXEC sp_OAGetErrorInfo @iReq, @errorSource OUTPUT, @errorDescription OUTPUT SELECT [Error Source] = @errorSource, [Description] = @errorDescription Raiserror('sp_OAMethod Send FAILED!', 16, 1) end else Begin EXEC @hr = sp_OAGetProperty @iReq,'responseText', @sResponse OUT print @hr insert into send_log (Id, mobile, sendtext, response, created, createddate) values(0, @MobileNo, @smstext, @sResponse, 'System', GETDATE())endend
Using the Above Stored Procedure and with SMS Gateway API - simply u can send sms to anybody - its a simple task
Just pass the parameters to Stored Procedure for which number you want to send sms. thats it.
i tested this using Sql Server 2008 with clickatell sms gateway.
Thanks friends This is my first POst
when i execute sp i got he following error
ReplyDeletecan u pl solve this erreor
SQL Server blocked access to procedure 'sys.sp_OAMethod' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.
@harshal
ReplyDeleteenable those Stored Procedures in sql server
hi
ReplyDeleteyes what u want
ReplyDeleteI know, it's late but still wish to make point clear:
ReplyDeleteBelow T-SQL need to be run in order to ensure that all those Stored Procedures are running.
sp_configure 'Ole Automation Procedures' , 1
RECONFIGURE
'http://api.clickatell.com/http/sendmsg?user=devendar&password=xxxxxxxxx&api_id=xxxxxxxx&to=#MobNo#&text=#Msg#'
ReplyDeletecould u please explain me where to get user,password,api_id and all. user=devendar ? password=xxxx ? api_id =xxx .? Here mentioned as xxx.
It will be really helpful for me to proceed further
ERR: 114, Cannot route message is showing as error. can u please clarify
ReplyDeletehttp://stackoverflow.com/questions/10088230/send-sms-using-triggers-and-stored-procedures-from-sql-server-2008
ReplyDeletecheck the above url .. this is also solved by me
Hi ,
ReplyDeletesorry to ask question again.when i try this in separate tab in browser, sms is going, whereas, inside the sp, it is not working. can u help me to solve this issue
hii
ReplyDeletei am new in sql so plz tell me how to run this procedure in sql
After 2 sms , againi have to restart the sql services again.
ReplyDeleteWhat's the problem , it will work only for 2 sms only.
It required to start sql service again after 2 sms why ?
- Ravi chaudhari - chaudhariravi@hotmail.com
The same issue i am facing.
DeleteAny Solution for After 2 sms , againi have to restart the sql services again.
DeleteWhat's the problem , it will work only for 2 sms only.
It required to start sql service again after 2 sms why ?
Process executing successfully.. but sms not sending
ReplyDeletemy url is === set @sUrl='https://powersms.banglaphone.net.bd/httpapi/sendsms?userId=XXXXX&password=**********&smsText=#Msg#&commaSeperatedReceiverNumbers=#MobNo#'
if i paste and execute in browser then sms sends successfully,
but not sending from SQL Server 2008 r2
NB : i have executed the following code first
USE [ISTCLAPSDB]
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1
GO
RECONFIGURE;
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE;
Can anybody help me about the problem.
hi your cUSE [ISTCLAPSDB]
DeleteGO
sp_configure 'show advanced options', 1
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1
GO
RECONFIGURE;
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE;
omment
Message Submitted
ReplyDeleteCredits Consumed: 2
Balance Credits: 98
Mobile=919822012345 MsgId=1177855328
Mobile=919370119223 MsgId=1177855329
how will i get output like this .....plz help me
i want this output to check wether msg gone or not
The stored procedure only executes twice and afer that, doesn't send the parameters to the third party. Please, i need a olution
ReplyDelete