In my SSIS package, I created ADO connection manager, so I have MyAdoManager.conmgr that has underlying connection named MyServerName.MyDbName.
Now, I'm trying to use it in the Script Task the way it's described in some manuals.
ConnectionManager cm;
System.Data.SqlClient.SqlConnection sqlConn;
System.Data.SqlClient.SqlCommand sqlComm;
cm = Dts.Connections["MyAdoManager.conmgr"]; // also tried "MyServerName.MyDbName"
sqlConn = (System.Data.SqlClient.SqlConnection)cm.AcquireConnection(Dts.Transaction);
sqlComm = new System.Data.SqlClient.SqlCommand("SELECT * FROM MyTable", sqlConn);
sqlComm.ExecuteNonQuery();
cm.ReleaseConnection(sqlConn);
The issue
After executing package, I always get an exception "Connection not found". How do I get access to the connection used by existing connection manager?
What connection name should I use here cm = Dts.Connections["..."]?
Also, I saw some suggestions that I need connection manager to the script box, but I don't have any connection related settings in the script editor in my SSIS.