2015-11-13 94 views
0

我有一個返回xml的存儲過程。此結果存儲在SSIS中的變量(類型爲object)中。該變量作爲參數傳遞給execute sql任務中的另一個存儲過程。參數映射完成爲varchar。我收到以下錯誤:XML參數映射錯誤

[Execute SQL Task] Error: Executing the query "exec uspDeleteLiveRecordAfterArchival ?" failed with the following error: "An error occurred while extracting the result into a variable of type (DBTYPE_STR)".

注:我肯定沒有錯,在存儲過程,因爲它單獨測試時工作正常。

這個參數映射有什麼問題,以及如何解決這個問題?

我搜索了很多,但我沒有看到任何有用的答案。

可變

enter image description here

enter image description here

參數映射

enter image description here

+1

我不認爲SSIS可以隱式轉換的對象變量爲varchar。您能否將第一個過程中的XML存儲在字符串變量中而不是對象中? –

回答

0

到目前爲止我無法使用Execute SQL任務。現在我從一個腳本任務調用存儲過程並分配給一個變量,直到我得到一個更好的解決方案。

腳本任務

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 

存儲過程的僞代碼

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