3

我已经搜遍了,现在我不得不问。我正在尝试使用 EzAPI 构建一个简单的数据流。这绝非易事,但我致力于解决这个问题。我不知道如何开始EzOleDBDestination工作。这是我的完整代码

var a = new Application();
// using a template since it's impossible to set up an ADO.NET connection to MySQL
//  using EzAPI and potentially even with the raw SSIS API...
var pkg = new EzPackage(a.LoadPackage(@"C:\...\Package.dtsx", null));
pkg.Name = "Star";

var df = new EzDataFlow(pkg);
df.Name = "My DataFlow";

var src = new EzAdoNetSource(df);
src.Name = "Source Database";
src.SqlCommand = "SELECT * FROM enum_institution";
src.AccessMode = AccessMode.AM_SQLCOMMAND;
src.Connection = new EzConnectionManager(pkg, pkg.Connections["SourceDB"]);
src.ReinitializeMetaData();

var derived = new EzDerivedColumn(df);
derived.AttachTo(src);
derived.Name = "Prepare Dimension Attributes";
derived.LinkAllInputsToOutputs();
derived.Expression["SourceNumber"] = "id"; 
derived.Expression["Name"] = "(DT_STR,255,1252)description";

// EDIT: reordered the operation here and I no longer get an error, but 
//  I'm not getting any mappings or any input columns when I open the package in the designer
var dest = new EzOleDbDestination(df);
dest.AttachTo(derived, 0, 0);
dest.Name = "Target Database";
dest.AccessMode = 0;
dest.Table = "[dbo].[DimInstitution]";
dest.Connection = new EzConnectionManager(pkg, pkg.Connections["TargetDB"]);

// this comes from Yahia's link
var destInput = dest.Meta.InputCollection[0];
var destVirInput = destInput.GetVirtualInput();
var destInputCols = destInput.InputColumnCollection;
var destExtCols = destInput.ExternalMetadataColumnCollection;
var sourceColumns = derived.Meta.OutputCollection[0].OutputColumnCollection;

foreach(IDTSOutputColumn100 outputCol in sourceColumns) {
    // Now getting COM Exception here...
    var extCol = destExtCols[outputCol.Name];
    if(extCol != null) {
        // Create an input column from an output col of previous component.
        destVirInput.SetUsageType(outputCol.ID, DTSUsageType.UT_READONLY);
        var inputCol = destInputCols.GetInputColumnByLineageID(outputCol.ID);
        if(inputCol != null) {
            // map the input column with an external metadata column
            dest.Comp.MapInputColumn(destInput.ID, inputCol.ID, extCol.ID);
        }
    }
}

基本上,任何涉及调用的ReinitializeMetadata()结果都会导致 0xC0090001,因为该方法是错误发生的地方。没有真正的文档可以帮助我,所以我必须依赖这里的任何大师。

我应该提到源数据库是 MySQL,目标数据库是 SQL Server。使用 SSIS 设计器构建这样的包效果很好,所以我知道这是可能的。

如果我做错了什么,请随时告诉我。

编辑:这是我用作模板的基本包的链接:http ://www.filedropper.com/package_1 。我已经编辑了连接细节,但是任何 MySQL 和 SQL Server 数据库都可以。该包将从 MySQL 中读取(使用 MySQL ADO.NET 连接器)并写入 SQL Server。

数据库模式大多无关紧要。为了测试,只需在 MySQL 中创建一个包含两列的表:id (int) 和 description (varchar),其中 id 是主键。在 SQL Server 中创建等效列。这里的目标只是从一个复制到另一个。在某些时候它可能最终会变得更加复杂,但我必须首先克服这个障碍。

4

2 回答 2

2

我现在无法对此进行测试,但我很确定以下内容将帮助您使其正常工作:

更新-根据评论,有关调试此问题的更多信息以及指向完整端到端示例的链接以及源代码:

于 2012-05-10T18:21:49.640 回答
1

I've had this exact same issue and been able to resolve it with a lot of experimentation. In short you must set the connection for both the source and destination, and then call the attachTo after both connections are set. You must call attachTo for every component.

I've written a blog about starting with an SSIS package as a template, and then manipulating it programmatically to produce a set of new packages.

The article explains the issue more.

于 2015-01-19T06:46:43.780 回答