我正在使用以下代碼從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_'並將其他內容用作前綴 - 或者根本沒有前綴! –
謝謝您的建議 –