Tuesday, March 10, 2009

SSIS: Using a Connection from the Connection Manager in your Script Task is Tricky!

In a SSIS package I created couple of days ago, I was trying to minimize the number of connection strings / objects in the package so that I can have less "values to configure" in the SSIS package config files.
In the package, I had a single OLEDB connection in the connection managers window, and I did the infamous access of the connection inside the scipt task hoping I can reuse, the error I got was:

"Unable to cast COM object of type 'System.__ComObject' to class type 'System.Data.OleDb.OleDbConnection'."

so I did some search and found this thread from technet
http://social.technet.microsoft.com/Forums/en-US/sqlintegrationservices/thread/7d9b3a46-9f90-4886-8a25-acabaf5d6a3f/

read the last post:
"Correct, if you want to use the connection object in a script, it must be ADO.NET, not OLE-DB, so that means two for you. The alternative is what the other posted attempted, using the connection string from an OLE-DB connection, to initialise a .NET connection object, but with the limitation of no password. if you use only integrated security it is a poissible solution."

So, I belive integration of connections between the package and the child scipt task still needs some work on the microsoft side. because now you have to either create two connections, one of type OLEDB and one of type ADO.Net, which will cause two config values in the ssis config file.
Or do it like what I did:
I created a package variable to hold the connection string and then I create my own object in the script task from this connection string, not that straightforward but the best I can do now.

happy ssis programming!
-Tamer

No comments: