Transactions connection association removed before disposing

Transactions connection association removed before disposing

Postby esben » 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:
Code: Select all
public IDbTransaction CreateTransaction()
{
var connection = this.connectionManager.CreateConnection();
connection.Open(),
return connection.BeginTransaction()
}


Now in the using code we often have something like the following:
Code: Select all
using(var transaction = repository.CreateTransaction())
{
// Do transaction stuff

transaction.Commit();
}


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:
Code: Select all
this.Connection = null;

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
Code: Select all
using(var transaction = repository.CreateTransaction())
using(var connection = transaction.Connection)
{
// Do transaction stuff

transaction.Commit();
}


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?
esben
 
Posts: 43
Joined: Tue 05 Jul 2011 09:40

Re: Transactions connection association removed before disposing

Postby Pinturiccio » Wed 04 Feb 2015 17:02

You are right, dotConnect for Oracle does not close a connection when a transaction related to this connection is committed. System.Data.SqlClient has the same behavior.

Please create and send us a small test project that demonstrates the case when dotConnect for Oracle does not close a connection after a transaction commit, and System.Data.SqlClient closes a connection in the same situation.
Pinturiccio
Devart Team
 
Posts: 2046
Joined: Wed 02 Nov 2011 09:44

Re: Transactions connection association removed before disposing

Postby esben » Thu 05 Feb 2015 08:51

I think you might have misunderstood.
The commit in SqlClient and OracleClient does not CLOSE the connection, but it keeps the connection associated with the transaction such that when you DISPOSE the transaction, the connection is also disposed (and therefore closed).

Of course its been a while since i actually had code using the System.Data.OracleClient and you are right the connection is not disposed when disposing the transaction and the connection is actually disassociated - so I was wrong and my old test were wrong as well.

So just ignore my previous post, sorry for not actually producing a small sample first!
esben
 
Posts: 43
Joined: Tue 05 Jul 2011 09:40

Re: Transactions connection association removed before disposing

Postby MariiaI » Fri 06 Feb 2015 09:04

If we understood you correctly, the issue has been resolved. Please confirm this, and, if you have any further questions, feel free to contact us.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for Oracle