Mil*_*abs 5 ssis database-connection script-component
我现在一直在寻找解决方案,我似乎仍然无法找到解决方案.我在脚本组件中获取连接时遇到问题.在将其插入之前,我需要查询我的数据库以检索要使用的Id
public override void AcquireConnections(object Transaction)
{
connMgr = base.Connections.Connection;
conn = (SqlConnection)connMgr.AcquireConnection(null);
}
Run Code Online (Sandbox Code Playgroud)
我在这里得到一个例外.
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.
Run Code Online (Sandbox Code Playgroud)
有解决方案吗
对于那些希望能够在脚本组件中执行此操作的人:
您可以在脚本中执行以下操作:
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);
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
8439 次 |
| 最近记录: |