﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Integration Services / Data Warehousing  / accessing connection managers in script tasks / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 22:47:10 GMT</lastBuildDate><ttl>20</ttl><item><title>accessing connection managers in script tasks</title><link>http://www.sqlservercentral.com/Forums/Topic1367072-364-1.aspx</link><description>Hello,I'm trying to use an OLEDB connection in a script task.  There's a fair amount of documentation on this topic, such as:http://msdn.microsoft.com/en-us/library/ms136018.aspx#Y718http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/dbf15acc-ed02-442d-8b56-4e170d7b89a2http://blogs.msdn.com/b/mattm/archive/2008/08/22/accessing-oledb-connection-managers-in-a-script.aspxThe only problem is I can't get anything to work.  (Nothing like examples that produce errors.)For example, when I mimic the code in the first link above with this VB.NET code:[code="vb"]Dim myConnection As SqlConnectionDim cm As ConnectionManagercm = Dts.Connections("DB_cm")myConnection = DirectCast(Dts.Connections("DB_cm").AcquireConnection(Dts.Transaction), SqlClient.SqlConnection)--OR--myConnection = DirectCast(cm.AcquireConnection(Dts.Transaction), SqlClient.SqlConnection)[/code]Then debug the package, I get this error on the "Directcast" line:[quote]System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.Data.SqlClient.SqlConnection'.[/quote]Does anyone have an idea why I can't get code in a Script Task to execute which also appears in the Microsoft KB?thanks,</description><pubDate>Tue, 02 Oct 2012 08:20:43 GMT</pubDate><dc:creator>cafescott</dc:creator></item></channel></rss>