Transactions connection association removed before disposing
Posted: Fri 30 Jan 2015 10:00
We have an issue with the way dotConnect for oracle removes the connection from a transaction before disposing it (thus it is not closed automatically).
In our code base the connection to the underlying provider is more or less hidden from the developer at all times such that he/she won't have to worry about it.
This includes cases where we need to do multiple things in a transaction.
We have a helper method that looks something like this:
Now in the using code we often have something like the following:
With the "old" default .NET Oracle and MSSQL Providers this will actually cause the connection to be closed when the scope end (i.e. dispose is called on transaction).
However because the dotConnect provider does something on "Commit" along the lines of:
The connection is no longer associated with the transaction once Commit has completed (and thus transaction.dispose won't close the connection).
So basically we now have to remember to do the following all the places we use transactions
I know this MIGHT be a design issue, or a breaking change to fix it, but it just seems a bit odd since the behavior is different from the .NET "bundled" providers.
Any chance you are going to change the behavior or will we have to write some sort of analyzer for our code to avoid connection leaks in the future?
In our code base the connection to the underlying provider is more or less hidden from the developer at all times such that he/she won't have to worry about it.
This includes cases where we need to do multiple things in a transaction.
We have a helper method that looks something like this:
Code: Select all
public IDbTransaction CreateTransaction()
{
var connection = this.connectionManager.CreateConnection();
connection.Open(),
return connection.BeginTransaction()
}
Code: Select all
using(var transaction = repository.CreateTransaction())
{
// Do transaction stuff
transaction.Commit();
}
However because the dotConnect provider does something on "Commit" along the lines of:
Code: Select all
this.Connection = null;
So basically we now have to remember to do the following all the places we use transactions
Code: Select all
using(var transaction = repository.CreateTransaction())
using(var connection = transaction.Connection)
{
// Do transaction stuff
transaction.Commit();
}
Any chance you are going to change the behavior or will we have to write some sort of analyzer for our code to avoid connection leaks in the future?