我正在使用以下代码从SQL Server 2014发送短信。它用于正常工作,但是有几天它不工作。我还在另一个SQL Server中执行了下面的代码,它工作得很好。但由于某种原因,不能在SQL Server 2014中工作。我还尝试在浏览器中使用url发送低谷,并且它也起作用。但一些如何我不通过存储过程工作。从SQL Server 2014 Issu Identification发送SMS Issu Identification
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
继结果
*
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.
备注:您应该**不要**为存储过程使用'sp_'前缀。微软已经保留了这个前缀以供自己使用(参见*命名存储过程*)](http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx),以及你将来有可能冒着名字冲突的风险。 [这对你的存储过程性能也是不利的](http://www.sqlperformance.com/2012/10/t-sql-queries/sp_prefix)。最好只是简单地避免使用'sp_'并将其他内容用作前缀 - 或者根本没有前缀! –
谢谢您的建议 –