我有一个返回xml的存储过程。此结果存储在SSIS中的变量(类型为object)中。此变量作为参数传递给execute sql task中的另一个存储过程。参数映射以varchar完成。我收到以下错误:
[执行SQL任务]错误:执行查询“exec uspDeleteLiveRecordAfterArchival?”失败并出现以下错误:“将结果提取到类型变量(DBTYPE_STR)时发生错误”。
注意:我确信存储过程没有任何问题,因为它单独测试时工作正常。
此参数映射有什么问题以及如何纠正此问题?
我搜索了很多,但我没有看到任何有用的答案。
可变
封装
参数映射
答案 0 :(得分:0)
脚本任务
Public Sub Main()
Dim tableName As String = Dts.Variables("User::CurrentTable").Value.ToString()
Dim sourceConnection As SqlConnection
Dim destinationConnection As SqlConnection
Try
Dim cmSource As ConnectionManager
cmSource = Dts.Connections("ADOSourceConnection")
sourceConnection = DirectCast(cmSource.AcquireConnection(Dts.Transaction), System.Data.SqlClient.SqlConnection)
Dim cmDestination As ConnectionManager
cmDestination = Dts.Connections("ADOACIConnection")
destinationConnection = DirectCast(cmDestination.AcquireConnection(Dts.Transaction), System.Data.SqlClient.SqlConnection)
Using destinationConnection
Dim cmd As New SqlCommand()
cmd.Connection = destinationConnection
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "uspGetIncompleteMoveFromArchival"
cmd.Parameters.AddWithValue("@TableName", tableName)
Dim result As String = Convert.ToString(cmd.ExecuteScalar())
Dts.Variables("User::IncompleteMoveXML").Value = result
'Release Connection'
cmSource.ReleaseConnection(sourceConnection)
cmDestination.ReleaseConnection(destinationConnection)
'Success'
Dts.TaskResult = Dts.Results.Success
End Using
Catch ex As Exception
Dim exceptionVariable As Microsoft.SqlServer.Dts.Runtime.Variables = Nothing
Dts.VariableDispenser.LockOneForWrite("User::ScriptException", exceptionVariable)
exceptionVariable("User::ScriptException").Value = ex.Message
exceptionVariable.Unlock()
Dts.Events.FireError(-1, "Task Name", ex.Message, String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
存储过程Psuedo代码
DECLARE @Result XML
SELECT @Result =
(
SELECT
'SKULocationsSnapShot' AS '@tableName',
(
SELECT CONVERT(VARCHAR(20), SnapShotID) AS SnapShotID,
CONVERT(VARCHAR(20), LocationID) AS LocationID
FROM dbo.SKULocationsSnapShot CurrentTable (NOLOCK)
WHERE IsMoveComplete = 'N'
FOR XML PATH('CurrentRow'), TYPE
)
FOR XML PATH('root')
)
SELECT CAST(
@Result
AS VARCHAR(MAX)
) AS IncompleteMoveXML