I am using this following code to send sms from SQL Server 2014. It used to work properly but for few days it is not working. I also executed the following code in another SQL Server and it is working perfectly. But for some reason not working in SQL Server 2014. I also try ed sending trough using url in an browser and it also works. but some how i does not work via stored procedure.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--EXEC sp_SendSmsSQL '*****','Today is Saturday',''
ALTER procedure [dbo].[sp_SendSmsSQL]
@MobileNo varchar(max),
@smstext as varchar(300),
@sResponse varchar(8000) 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
--EXEC @hr = sp_OACreate 'MSXML2.ServerXMLHTTP', @iReq OUT
print '*'
print 'hr : ' + cast(@hr as varchar)
if @hr <> 0
Raiserror('sp_OACreate Microsoft.XMLHTTP FAILED!', 16, 1)
set @sUrl='****'
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 '**'
print @hr
if @hr <> 0
Raiserror('sp_OAMethod Open FAILED!', 16, 1)
EXEC @hr = sp_OAMethod @iReq, 'Send'
select @iReq
print '***'
print 'hr : ' + cast(@hr as varchar)
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
print '****'
print @sresponse
end
EXEC @hr=sp_OADestroy @iReq
print @hr
DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS
END
Following the results
*
hr : 0
url ='******'
**
0
(1 row(s) affected)
***
hr : 0
-2147483638
****
0
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.