EzAPI OLE DB Destination

3

I've searched all over and I now have to ask SO. I'm trying to construct a simple dataflow using EzAPI. It's been anything but easy, but I'm committed to figuring this out. What I can't figure out is how to get the EzOleDBDestination working. Here's my complete code

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);
        }
    }
}

Basically, anything that involves calls to ReinitializeMetadata() results in 0xC0090001, because that method is where the error happens. There's no real documentation to help me, so I have to rely on any gurus here.

I should mention that the source DB is MySQL and the target DB is SQL Server. Building packages like this using the SSIS designer works fine, so I know it's possible.

Feel free to tell me if I'm doing anything else wrong.

EDIT: here's a link to the base package I'm using as a template: http://www.filedropper.com/package_1 . I've redacted the connection details, but any MySQL and SQL Server database will do. The package will read from MySQL (using the MySQL ADO.NET Connector) and write to SQL Server.

The database schema is mostly irrelevant. For testing, just make a table in MySQL that has two columns: id (int) and description (varchar), with id being the primary key. Make equivalent columns in SQL Server. The goal here is simply to copy from one to the other. It may end up being more complex at some point, but I have to get past this hurdle first.

c#
com
ssis
ezapi
asked on Stack Overflow May 7, 2012 by siride • edited May 10, 2012 by siride

2 Answers

2

I can't test this now BUT I am rather sure that the following will help you get it working:

UPDATE - as per comments some more information on debugging this and a link to a complete end-to-end sample with source:

answered on Stack Overflow May 10, 2012 by Yahia • edited May 10, 2012 by Yahia
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.

answered on Stack Overflow Jan 19, 2015 by agilmore

User contributions licensed under CC BY-SA 3.0