gpt4 book ai didi

SSIS 脚本组件连接

转载 作者:行者123 更新时间:2023-12-04 18:11:16 25 4
gpt4 key购买 nike

几天来我一直在寻找解决方案,但似乎仍然找不到。我在我的脚本组件中获取连接时遇到问题。我需要查询我的数据库以检索要使用的 ID,然后再将其插入

public override void AcquireConnections(object Transaction)
{
connMgr = base.Connections.Connection;
conn = (SqlConnection)connMgr.AcquireConnection(null);
}

我这里有一个异常(exception)。
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.Data.SqlClient.SqlConnection'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

任何解决方案?

最佳答案

对于那些希望能够在脚本组件中执行此操作的人:

  • 双击脚本组件打开“脚本转换编辑器”
  • 单击“连接管理器”列表项。
  • 添加新的连接管理器。选择现有的 ADO.NET 连接管理器。
  • 单击“脚本”列表项,然后单击“编辑脚本...”按钮。

  • 您可以在脚本中执行以下操作:
    using (SqlConnection connection = this.Connections.Connection.AcquireConnection(null) as SqlConnection)
    {
    using (SqlCommand command = connection.CreateCommand())
    {
    command.CommandText = "SELECT [Value] FROM dbo.MyTable";
    command.CommandType = CommandType.Text;

    using (SqlDataReader reader = command.ExecuteReader())
    {
    while (reader.Read())
    {
    ProfanityWords.Add(reader.GetValue(0).ToString());
    }
    }
    }

    this.Connections.Connection.ReleaseConnection(connection);
    }

    enter image description here

    关于SSIS 脚本组件连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13578304/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com