Page 1 of 1

Accessing an existing connection from an SSIS Script Component

Posted: Fri 24 Apr 2020 08:50
by lb483
I'm using the MySqlLoader in an SSIS script component (C#) as it gives significant performance benefits over other methods.

However as part of the code, I'm having to create a new MySqlConnection object to open the target database. As the package already contains a connection manager to the database, is it possible to make use of this without having to create a new one?

Code: Select all

MySqlConnection mySqlConnx = (MySqlConnection)Connections.Connection;
results in the error:

Code: Select all

Unable to cast COM object of type 'System.__ComObject' to class type 'Devart.Data.MySql.MySqlConnection'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
Is there a way to reuse this existing component? My current workaround is:

Code: Select all

MySqlConnection mySqlConnx = new MySqlConnection(Connections.Connection.ConnectionString);
mySqlConnx.Password = "***";
If I could reuse the existing connection manager, I wouldn't have to code in the password but I can't find a way to do this.

Thanks.

Re: Accessing an existing connection from an SSIS Script Component

Posted: Fri 24 Apr 2020 16:30
by Shalex