How to send message using database

Ankit tewari
Ankit t...
112 Points
11 Posts

how can Send SMS using  stored procedures from SQL Server 2008 

Views: 9970
Total Answered: 2
Total Marked As Answer: 0
Posted On: 30-Jan-2018 10:35

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
4916 Points
27 Posts
         

There is no in-build method to sending SMS but you can use external xmlhttp api in store procedure. See following thread for more detail https://www.niceonecode.com/Q-A/SQL/Query/Send-SMS--Email-Using-Backend-/20396

Feel free to ask if any issue.

Posted On: 31-Jan-2018 03:29
nik
nik
166 Points
6 Posts
         

Use following, where @sUrl is SMS send api url with parameters:

Create PROCEDURE SP_CallWebService @sUrl NVARCHAR(MAX)
AS
BEGIN  
  DECLARE @iReq INT,
    @hr INT
  DECLARE @errorSource VARCHAR(8000)
  DECLARE @errorDescription VARCHAR(8000)
  DECLARE @sResponse NVARCHAR(MAX)
  EXEC @hr = sp_OACreate 'Microsoft.XMLHTTP',@iReq OUT

  EXEC @hr = sp_OAMethod @iReq,'Open',NULL,'GET',@sUrl,'false'
  if @hr<>0
        print ' Failed in sp_OAMethod open'
  EXEC @hr = sp_OAMethod @iReq,'send'
  if @hr<>0
        print ' Failed in sp_OAMethod send'
  BEGIN
    set @hr=0
    EXEC @hr = sp_OAGetProperty @iReq,'responseText',@sResponse OUT
    if @hr<>0
        print ' Failed in sp_OAGetProperty'
  END
  
  EXEC sp_OADestroy @iReq
  EXEC sp_OADestroy @hr
END
GO
Posted On: 01-Feb-2018 23:46
 Log In to Chat