Building Connectors Is Crap in SSIS

What else can I say. I finally broke when I had to build a flat file connector with 258 columns that needed to be imported into a staging database. 258 columns… I almost had a stroke. Not only is it mind numbing it’s also error prone. I do dabble in c# so I build a little tool to automate this for me.

Introducing SSISConnectionBuilder

SSISConnectionBuilder is a simple command line tool to ease the burden of building flat file connectors for SSIS. It is WAY WAY alpha but I am working on cleaning up the code. You can pick it up here on codeplex.

I have only tested this on Windows 8/7 64 bit. If you get an error about cannot find DLL you need to install the client development stuff from the SQL Server installer.

You need to generate an excel spreadsheet with four columns. Column,Type,Precision,Scale.

The program loops through the sheet and kicks out an SSIS dtsx file with a single flat file connector defined.

You can choose a delimiter, package name and set the csv file name for the connector. The csv file name doesn’t have to be valid. If you know the csv file will be unicode you need to pass the -u or you will have errors with your connector with the error column being ntext instead of text.
Command line options:
-s, –schemafile =VALUE Your excel schema definition file.
-d, –delimiter=VALUE The column separator you wish to use, usually a comma or pipe.
-p, –packagename=VALUE Name of the dtsx file that will have your connection in.
-c, –csvfilename=VALUE Name of the csv file that your connection will use.
-u, –unicode csv file is Unicode.
-?, -h, –help show this message and exit

To generate the schema spread sheet you can run one of these queries against your table and just cut and paste into a new spread sheet.

–SQL Server 2012
SELECT ’Column’ = sc.name,
‘Type’ = st.name,
‘precision’ = CASE st.name
WHEN ’decimal’ THEN sc.PRECISION
WHEN ’numeric’ THEN sc.PRECISION
WHEN ’float’ THEN sc.PRECISION
WHEN ’time’ THEN sc.scale
WHEN ’datetimeoffset’ THEN sc.scale
WHEN ’varbinary’ THEN sc.max_length
WHEN ’varchar’ THEN sc.max_length
WHEN ’binary’ THEN sc.max_length
WHEN ’char’ THEN sc.max_length
WHEN ’nvarchar’ THEN sc.max_length
WHEN ’nchar’ THEN sc.max_length
ELSE 0
END,
‘scale’ = CASE st.name
WHEN ’decimal’ THEN sc.scale
WHEN ’numeric’ THEN sc.scale
ELSE 0
END
FROM   sys.objects o
INNER JOIN sys.columns sc
ON o.object_id = sc.object_id
INNER JOIN sys.types st
ON sc.user_type_id = st.user_type_id
WHERE  o.name = ’datatypes’

–SQL Server 2005
SELECT ’Column’ = sc.name,
‘Type’ = st.name,
‘precision’ = CASE st.name
WHEN ’decimal’ THEN sc.PRECISION
WHEN ’numeric’ THEN sc.PRECISION
WHEN ’float’ THEN sc.PRECISION
WHEN ’varbinary’ THEN sc.max_length
WHEN ’varchar’ THEN sc.max_length
WHEN ’binary’ THEN sc.max_length
WHEN ’char’ THEN sc.max_length
WHEN ’nvarchar’ THEN sc.max_length
WHEN ’nchar’ THEN sc.max_length
ELSE 0
END,
‘scale’ = CASE st.name
WHEN ’decimal’ THEN sc.scale
WHEN ’numeric’ THEN sc.scale
ELSE 0
END
FROM   sys.objects o
INNER JOIN sys.columns sc
ON o.object_id = sc.object_id
INNER JOIN sys.types st
ON sc.user_type_id = st.user_type_id
WHERE  o.name = ’datatypes’

–SQL Server 2000
SELECT ’Column’ = sc.name,
‘Type’ = st.name,
‘precision’ = CASE st.name
WHEN ’decimal’ THEN sc.xprec
WHEN ’numeric’ THEN sc.xprec
WHEN ’float’ THEN sc.xprec
WHEN ’varchar’ THEN sc.length
WHEN ’binary’ THEN sc.length
WHEN ’char’ THEN sc.length
WHEN ’nvarchar’ THEN sc.length
WHEN ’nchar’ THEN sc.length
ELSE 0
END,
‘scale’ = CASE st.name
WHEN ’decimal’ THEN sc.xscale
WHEN ’numeric’ THEN sc.xscale
ELSE 0
END
FROM   syscolumns sc
INNER JOIN systypes st
ON sc.xusertype = st.xusertype
INNER JOIN sysobjects o
ON sc.id = o.id
WHERE  o.name = ’datatypes’

The post Building Flat File Connectors Dynamically For SSIS appeared first on .