【问题标题】:SSIS Script Task Error. Fill: SelectCommand.Connection property has not been initializedSSIS 脚本任务错误。填充:SelectCommand.Connection 属性尚未初始化
【发布时间】:2021-07-22 14:09:12
【问题描述】:

根据我在网上找到的搜索结果,我尝试了几种不同的方法。

我正在处理一个 SSIS 脚本任务,它将执行一个需要将 TVP 参数传递给它的存储过程。我已经把所有的东西都连接好并且工作正常,但是当它到达da.Fill(resultDT) 我得到了错误:

填充:SelectCommand.Connection 属性尚未初始化。

OleDbDataAdapter A = new OleDbDataAdapter();
DataTable dt = new DataTable();

A.Fill(dt, Dts.Variables["User::Companies"].Value);

DataTable resultDT = new DataTable();

using (SqlConnection sqlcon = (SqlConnection)(Dts.Connections["RegistryConnection"].AcquireConnection(Dts.Transaction) as SqlConnection))
{
    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.Connection = sqlcon;
        cmd.CommandText = "[Registry].[GetClientData_ByCompanyIDs]";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@companyIDs", dt);

        using (SqlDataAdapter da = new SqlDataAdapter())
        {
            da.SelectCommand = cmd;
            da.Fill(resultDT);
            Dts.Variables["User::Clients"].Value = resultDT;
        }
    }
}

任何想法我错过了什么?希望我忽略了一些简单的事情。

【问题讨论】:

  • 好吧,没关系,问题是我使用的连接管理器。我最初将此设置为 OLEDB,但后来将其切换到 ADO.Net。但我从未改变过连接。显然 (SqlConnection)(Dts.Connections["RegistryConnection"].AcquireConnection(Dts.Transaction) as SqlConnection) 行实际上并未返回 SQLConnection 对象,因此未正确初始化 SelectCommand。将连接管理器修复为 ADO.Net 连接即可解决此问题!

标签: c# datatable ssis sqlconnection sqldataadapter


【解决方案1】:

问题是我使用的是 OLEDB 连接管理器,显然无法按照我的方式将其转换为 SQLConnection。

需要设置 ADO.Net 连接管理器,然后 SQLConnection 强制转换按预期工作。

问题解决了。

【讨论】:

    猜你喜欢
    • 2017-10-01
    • 2011-08-10
    • 2014-04-20
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 2014-03-06
    相关资源
    最近更新 更多