After much messing around with the BI studio I've decided that the best way for me to build my FFC is by doing it in code. I've got over 400 columns to define and we already have the position and type information held elsewhere, so it kinda makes sense doing this programmatically.
I've read the "Adding Connections to a Package" article in BOL but it doesn't help with the problem I've got. Basically, all I want to do is add columns to a connector but I have no idea if I'm going about this the right way.
Here's an example of how I'm creating the connection manager and getting access to the columns.
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts;
using Microsoft.SqlServer.Dts.Runtime;
static void Main(string[] args) {
Package package = new Package();
ConnectionManager cm = package.Connections.Add("FLATFILE");
object comColumns = cm.Properties["Columns"];.GetValue(cm);
}
The variable comColumns returns a IDTSConnectionManagerFlatFileColumns90 COM interface which allows me to add columns using the IDTSConnectionManagerFlatFileColumn90 interface. However, both of these interfaces are infrastructure use only and the IDTSConnectionManagerFlatFileColumn90 interface doesnt contain a name or ID field (like the FlatFileColumn class does) and I will need to complete these.
It actually feels like I should be using the ConnectionManagerFlatFileClass and FlatFileColumn classes but I can't see any way of using them.
Any help would be very much appreciated.
Thanks
Steve
Hi Steve,
here is a little sample that might help you. It is setting one delimited flat file column. Assuming the parameters on the right side are available.
IDTSConnectionManagerFlatFileColumn90 column = columns.Add();
column.DataPrecision = precision;
column.DataScale = scale;
column.DataType = dataType;
column.MaximumWidth = size;
column.ColumnDelimiter = delimiter;
column.ColumnType = "Delimited";
column.ColumnWidth = 0;
column.TextQualified = true;
// Here is how you set the name, do not worry about the ID.
IDTSName90 name = column as IDTSName90;
name.Name = columnName;
You know that some other properties (like ConnectionString, Format, TextQualifier, etc) on the connection have to be set as well, right?
Thanks,
No comments:
Post a Comment