Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net SSIS脚本任务中的OleDbCommand.ExecuteOnQuery()函数中存在未指定的错误_Vb.net_Ssis - Fatal编程技术网

Vb.net SSIS脚本任务中的OleDbCommand.ExecuteOnQuery()函数中存在未指定的错误

Vb.net SSIS脚本任务中的OleDbCommand.ExecuteOnQuery()函数中存在未指定的错误,vb.net,ssis,Vb.net,Ssis,我有一个SSIS包,它有一个FOREACH循环容器,在循环中我有一个脚本任务。脚本任务中的代码如下所示 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.

我有一个SSIS包,它有一个FOREACH循环容器,在循环中我有一个脚本任务。脚本任务中的代码如下所示

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
问题是-当执行包时,ExecuteOnQuery()抛出异常,显示“未指定的错误”

尝试使用类似的代码插入整数值时没有错误。当我将数据表作为输入参数传递给SP时,会导致该问题


有什么办法可以避免这种情况吗?

我认为您缺少的是告诉参数它应该是什么TVP以及它的类型(最后2行)。我的语言是C#,但同样的概念也适用

    command = new System.Data.SqlClient.SqlCommand("TwitterAdd");
    command.CommandType = System.Data.CommandType.StoredProcedure;
    command.Connection = connection;

    // Assigning a table valued parameter looks much like any other parameter
    System.Data.SqlClient.SqlParameter tvp = command.Parameters.AddWithValue("@tvp", dataTable);

    // this is the only special sauce
    tvp.SqlDbType = System.Data.SqlDbType.Structured;
    tvp.TypeName = "dbo.MY_TABLE_VALUED_PARAMETER";

这在VB中应该是相同的减去分号。

我遇到了相同的问题。我收到的错误消息是: 由于符号不匹配或数据溢出以外的原因,无法转换命令参数[0]“”数据值

在上面引用的MSDN文章中,我看不到任何对OLE DB的引用-TVPs似乎只是SqlClient

此外,在
System.Data.OleDB.OleDbType
枚举中,没有结构化的选项


我将OLEDB连接更改为ADO.Net连接,工作正常。

您无法将
数据表
传递到存储过程。您需要使用表值参数(TVP)或xml。请查看此MSDN链接
http://msdn.microsoft.com/en-us/library/bb675163.aspx
谢谢@billinkc。我想在我之前的练习中,我能够使用SQLConnection完成这项任务。但这里我必须使用OleDbconnection本身,以便将对象源数据中的数据填充到数据表中(使用oleDA.fill方法)。当我使用OLEDB连接时,datatable出现问题。
    command = new System.Data.SqlClient.SqlCommand("TwitterAdd");
    command.CommandType = System.Data.CommandType.StoredProcedure;
    command.Connection = connection;

    // Assigning a table valued parameter looks much like any other parameter
    System.Data.SqlClient.SqlParameter tvp = command.Parameters.AddWithValue("@tvp", dataTable);

    // this is the only special sauce
    tvp.SqlDbType = System.Data.SqlDbType.Structured;
    tvp.TypeName = "dbo.MY_TABLE_VALUED_PARAMETER";