Reuse existing DatabaseConnection in SqlBulkCopy

Hi there!

I have several processes using common library for establishing a connection to database. As an output this library returns object of type UiPath.Database.DatabaseConnection

Recently I found out that standard Insert activity takes long time to insert DataTable, containing several thousand records, into Database - for example, 2300 records are inserted in 7.5 minutes. Not quite performant. So I developed new library which inserts DataTable using SqlBulkCopy class and it handles much faster: abovementioned 2300 records are now uploaded in 4 sec. only - speed up is really enormous!
The problem is that SqlBulkCopy accepts SqlConnection instance or connection string for actually connecting to a database. Is there any way to feed somehow instance of DatabaseConnection type to SqlBulkCopy? Probably DatabaseConnection can be converted to SqlConnection type, or connection string may be extracted from DatabaseConnection…

Thanks in advance!

Hi @AmiD_FLice ,

Its better if you use invoke code activity and use it there rather than converting the dbcon to sqlcon or any other stuff
i done the same.

Don’t introduce black boxes when you don’t need to.

There is a Connection activity that allows you to connect to a db and then output the connection to a variable that you can then use as an input to other activities. If you go this route just make sure you close the connection after you’re done.