使用 sql 服务器 2012 发送短信
send SMS using sql server 2012
我正在尝试使用来自 sql 服务器的网络 api 发送短信。我在 sp_OAMethod
中有错误。下面写的是相同的代码
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
BEGIN
Raiserror('sp_OACreate Microsoft.XMLHTTP FAILED!', 16, 1)
SET @sUrl='http://alerts.ebensms.com/api/v3/?method=sms&api_key=******&to=#MobNo#&sender=XXXX&message=#Msg#'
SET @sUrl=REPLACE(@sUrl,'#MobNo#','0000000000')
SET @sUrl=REPLACE(@sUrl,'#Msg#','Thanks')
SELECT @sUrl
---- sms code start
EXEC @hr = sp_OAMethod @iReq, 'Open', NULL, 'GET', @sUrl,true
PRINT @hr
END
IF @hr <> 0
Raiserror('sp_OAMethod Open FAILED!', 16, 1)
EXEC @hr = sp_OAMethod @iReq, 'send'
SELECT @iReq
PRINT 'open failed'
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'
PRINT @hr
INSERT INTO tblUnCandidateSendSMSLog (Id,mobile,sendtext,created) values (12,'0000000000','send','AAAAAAA-B23C80FD16D4')
END
EXEC sp_OAGetErrorInfo
错误与
有关
sp_OAMethod @iReq, 'Open', NULL, 'GET', @sUrl,true
其中说发送失败。
此问题现已由
解决
sp_OAMethod @iReq, 'Open', NULL, 'POST', @sUrl,false
并改变
sp_OACreate 'Microsoft.XMLHTTP', @iReq OUT
到
sp_OACreate 'MSXML2.XMLHTTP', @iReq OUT;
我正在尝试使用来自 sql 服务器的网络 api 发送短信。我在 sp_OAMethod
中有错误。下面写的是相同的代码
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
BEGIN
Raiserror('sp_OACreate Microsoft.XMLHTTP FAILED!', 16, 1)
SET @sUrl='http://alerts.ebensms.com/api/v3/?method=sms&api_key=******&to=#MobNo#&sender=XXXX&message=#Msg#'
SET @sUrl=REPLACE(@sUrl,'#MobNo#','0000000000')
SET @sUrl=REPLACE(@sUrl,'#Msg#','Thanks')
SELECT @sUrl
---- sms code start
EXEC @hr = sp_OAMethod @iReq, 'Open', NULL, 'GET', @sUrl,true
PRINT @hr
END
IF @hr <> 0
Raiserror('sp_OAMethod Open FAILED!', 16, 1)
EXEC @hr = sp_OAMethod @iReq, 'send'
SELECT @iReq
PRINT 'open failed'
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'
PRINT @hr
INSERT INTO tblUnCandidateSendSMSLog (Id,mobile,sendtext,created) values (12,'0000000000','send','AAAAAAA-B23C80FD16D4')
END
EXEC sp_OAGetErrorInfo
错误与
有关sp_OAMethod @iReq, 'Open', NULL, 'GET', @sUrl,true
其中说发送失败。
此问题现已由
解决sp_OAMethod @iReq, 'Open', NULL, 'POST', @sUrl,false
并改变
sp_OACreate 'Microsoft.XMLHTTP', @iReq OUT
到
sp_OACreate 'MSXML2.XMLHTTP', @iReq OUT;