Sunday, 12 February 2012

Configuring Flat File Connection Programmatically?

I am programmatically creating a package in c#. I need this package to contain a flat file connection manager. I have been successfully able to create the connection manager with the following code:

Package p = new Package(); //New package

ConnectionManager cm = p.Connections.Add("FLATFILE"); //Add a flat file connection manager

cm.ConnectionString = "C:\Dev\myTestFile.txt"; //Set up the connection string

At this point, I want to configure the flat file specific properties of the connection manager (RowDelimiter, HeaderRowDelimiter, etc.). The problem is that the properties collection of the ConnectionManager object is read only. I think I could access the inner object of the connection manager and set the properties in the following way:

ConnectionManagerFlatFileClassffClass = (ConnectionManagerFlatFileClass) cm.InnerObject; //Get the inner object

ffClass .RowDelimiter = "{LF}"; //Set the properties here

Even if this would work, I do not like the solution b/c the BOL states that the ConnectionManagerFlatFileClass "supports the SQL Server 2005 infrastructure and is not intended to be used directly from your code". Does anyone know the "right" way to set these properties?

Many thanks in advance!

David

Figured it out - it looks like I spoke too soon - the BOL does indeed state how to do this:

cm.Properties["RowDelimiter"].SetValue(cm, "LF");

No comments:

Post a Comment