我有一个SSIS包,它有一个FOREACH循环容器,并且在循环中有一个脚本任务。在脚本任务的代码,作为以下给出SSIS脚本任务中的OleDbCommand.ExecuteNonQuery()函数中的未指定错误
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Configuration
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Public Sub Main()
Try
Dim oleConn As New OleDbConnection()
Dim strConn As String = Dts.Variables("ConfiguredValue").Value.ToString()
oleConn.ConnectionString = strConn
Dim oleDA As New OleDbDataAdapter()
Dim dt As New DataTable()
oleDA.Fill(dt, Dts.Variables("Source_Data").Value)
oleConn.Open()
Dim oleComm As New OleDbCommand("Insert_Into_Destination")
oleComm.CommandType = CommandType.StoredProcedure
oleComm.Connection = oleConn
oleComm.Parameters.AddWithValue("@tvp", dt)
oleDA.InsertCommand = oleComm
oleComm.ExecuteNonQuery()
oleConn.Close()
Catch ex As Exception
Throw ex
End Try
End Sub
End Class
值的变量Dts.Variables(“ConfiguredValue”)。在的每次迭代对于每个容器价值的变化。它看起来像 -
"Data Source=server_name;Initial Catalog=db_name;User ID=user_id;Password = Password;Provider=SQLOLEDB.1; Persist Security Info=True;Integrated Security=SSPI;Auto Translate=False;"
的问题是 - 当执行包有在为ExecuteNonQuery(品),显示“未指定的错误”引发的异常。
当我尝试类似的代码插入一个整数值时没有错误。当它是我作为输入参数传递给SP的数据表时会引发问题。
任何解决方案,以避免这种情况?
您无法将DataTable传递给存储过程。您需要使用表值参数(TVP)或xml。查看此MSDN链接http://msdn.microsoft.com/en-us/library/bb675163.aspx' – praveen