可以将 OleDbConnections 与脚本组件一起使用吗? [英] It's possible to use OleDbConnections with the Script Component?

查看:25
本文介绍了可以将 OleDbConnections 与脚本组件一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 ssis 包,我希望在脚本组件中使用现有的 OleDbConnection.这是我的代码:

I'm building an ssis package and I wish to use an existing OleDbConnection inside the Script Component. Here is my code:

public override void AcquireConnections(object Transaction)
{
    base.AcquireConnections(Transaction);
    cm = this.Connections.Connection;
    con = (OleDbConnection)cm.AcquireConnection(Transaction);
    MessageBox.Show(con.ToString());

}

当我关闭 BIDS 时,我收到以下消息:System.InvalidCastException:无法将System.__ComObject"类型的 COM 对象转换为System.Data.OleDb.OleDbConnection"类型.代表 COM 组件的类型的实例不能转换为不代表 COM 组件的类型;但是只要底层 COM 组件支持对接口 IID 的 QueryInterface 调用,它们就可以转换为接口."

When I close BIDS, i get the following message: "System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.Data.OleDb.OleDbConnection'. 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 连接上运行良好.这里可以使用OleDbConnection还是Script Component只支持Ado.Net?

The same code works fine with an Ado.Net connection. Can I use OleDbConnection here or Script Component only supports Ado.Net?

提前致谢.

推荐答案

谢谢 praveen.

Thanks praveen.

我在您的链接中找到了相关部分:

I found the relevant part in your link:

"如果您必须调用返回非托管对象的连接管理器的 AcquireConnection 方法,请使用 ADO.NET 连接管理器.当您将 ADO.NET 连接管理器配置为使用 OLE DB 提供程序时,它会连接通过使用 OLE DB 的 .NET Framework 数据提供程序.在这种情况下,AcquireConnection 方法返回 System.Data.OleDb.OleDbConnection 而不是非托管对象.配置 ADO.NET 连接管理器以与Excel 数据源,选择 Microsoft OLE DB Provider for Jet,指定 Excel 文件,然后在连接管理器对话框的所有页面上输入 Excel 8.0(对于 Excel 97 及更高版本)作为扩展属性的值."

"If you must call the AcquireConnection method of a connection manager that returns an unmanaged object, use an ADO.NET connection manager. When you configure the ADO.NET connection manager to use an OLE DB provider, it connects by using the .NET Framework Data Provider for OLE DB. In this case, the AcquireConnection method returns a System.Data.OleDb.OleDbConnection instead of an unmanaged object. To configure an ADO.NET connection manager for use with an Excel data source, select the Microsoft OLE DB Provider for Jet, specify an Excel file, and enter Excel 8.0 (for Excel 97 and later) as the value of Extended Properties on the All page of the Connection Manager dialog box."

谢谢!

这篇关于可以将 OleDbConnections 与脚本组件一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆