我有一个连接到SQL Server 2005后端的Access ADP。我正在尝试实现一个存储过程来更新我们客户的地址,这需要我使用xp_cmdshell
从命令行执行一个程序。该过程在SSMS中运行良好,但当我通过ADO连接对象从Access VBA调用它时,它会产生以下"错误":
运行时错误"-2147217900"(80040e14):配置选项"show"高级选项"已从0更改为1。运行RECONFIGURE语句要安装。
这并不是真正的错误——这是SQL Server在执行sp_configure
时生成的标准消息。存储过程确实调用了RECONFIGURE
,但由于某种原因,Access将该消息解释为错误。
你知道我怎么才能停止这种事吗?
值得一提的是,以下是我正在使用的一些代码。这是启用/禁用xp_cmdshell
:的存储过程
ALTER PROCEDURE [dbo].[spEnableXpCmdShell]
(@enabled bit)
WITH EXECUTE AS 'NKAjrosenberg'
AS
SET NOCOUNT ON
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', @enabled
RECONFIGURE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE
这是从我的主sp中调用的,它相当长,就像这样:
EXEC [dbo].[spEnableXpCmdShell] 1
最后,这里有一个有点删节的VBA代码版本:
Public Function DoNCOA(con, Optional caseId = Null, _
Optional docId = Null) As Integer
'Call the NCOAProces stored procedure asynchronously.
'Returned integer is not success or failure, but position in the queue
On Error GoTo ErrHandler
Dim cmd As New ADODB.Command, _
prm As ADODB.Parameter
With cmd
.ActiveConnection = con
.CommandText = "spNCOAProcess"
.CommandType = adCmdStoredProc
.CommandTimeout = 1800
Set prm = .CreateParameter("CaseID", adInteger, adParamInput, , caseId)
.Parameters.Append prm
Set prm = .CreateParameter("DocID", adInteger, adParamInput, , docId)
.Parameters.Append prm
.Execute Options:=adAsyncExecute, adExecuteNoRecords
End With
[...That's all the important stuff]
End Function
任何帮助都将不胜感激!
在try/catch块中运行sp_configure,这样就不会向客户端返回消息,怎么样?http://msdn.microsoft.com/en-us/library/ms175976(v=sql.90).aspx