[BulkInsert] Will it leak database connection when encounter error?
Question
bulkinsert
Service icon
Forge component by Galter
Application Type
Service

After checking bulkinsert source code, I found that we didn't call IDbConnection.Close in finally block. 

Recently Our server is done due to db connection pool exhausted.  


BulkInsert use the Main Transaction of HTTP Request.(just like Aggregate / Advance SQL)
So we NEED NOT commit / rollback or close db connection. 
Because OutSystems will commit and close db connection when Request finished.

According to the exception message [string or binary would be truncated]
The root cause is quite simple.
You had some text attributes, but value of your data had exceed the max length of attribute.
So you need check and find the attribute value that caused this error.
And then change the max length of related attribute.

Regards
Wei





Yes, we are fixing the root cause. 

My concern is that if we use bulkinsert in a light process,  is it still true that we need not to close?

I had reviewed the source code.

It seems the issue is it should use [C# using clause] for RequestTransaction.
This is recommended by OutSystems as following sample.
https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/RuntimePublic.Db_API/Call_a_stored_procedure

But you still should not close dbconnection because you had active transaction that managed by OutSystems.
If you close dbconnection , it will cause unexpected behaviour.

Regards
Wei

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.