Change IsolationLevel without explicitly starting a transaction

Posts   
 
    
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 07-Aug-2013 10:47:17   

I am using LLBLGen 4.0 with LLBLGen Pro Runtime Framework, Adapter. I want to accomplish a simple task: change the isolation level on the connection.

I know that this can be done by starting and immediately committing a dummy transaction; but this ugly. Is there another way to accomplish this?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-Aug-2013 17:55:21   

Isolation level for transactions, please check the following thread. http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=21632 This one might be useful too. http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=21404

Start a transaction specifying the Isolation level, use the transaction and then commit it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Aug-2013 16:35:20   

Connections don't have isolation levels, transactions do. I'm not sure why you would want this (as in: what you are trying to accomplish?) simple_smile

Frans Bouma | Lead developer LLBLGen Pro
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 10-Sep-2013 08:16:22   

Sorry for the late answer.

@Walaa: thanks, that's what I am already doing, but it is quite ugly.

@Otis: It is my understanding that (at least in SQL Server) each query issued on a connection with no running transaction will be run inside an implicit transaction. The isolation level used for these transactions can be changed using "set transaction isolation level xxx." This value is saved for each connection, which is what I meant in my earlier post. (If you open the profiler and list the existing connections, its shows a bunch of session-related SET statements, of which the isolation level is one.)

So what I would like to do is issue a "set transaction isolation level xxx" statement at runtime, without using T-SQL in an action query.

I want to do this to change the isolation level temporarily to READ UNCOMMITTED to allow dirty reads on a bunch of queries. I want to revert this change when I am done, because that's what the caller of my code expects me to do.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Sep-2013 08:48:33   

To tell LLBLGen to use some IsolationLevel when it needs to use a transaction implicitly (i.e. updates) you can do this way:

using (var adater = new DataAccessAdapter())
{               
    adater.TransactionIsolationLevel = IsolationLevel.ReadUncommitted;
    
    // ...
}
David Elizondo | LLBLGen Support Team
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 10-Sep-2013 08:59:00   

I know; but I cannot open a new DataAccessAdapter. Setting the TransactionIsolationLevel property after the adapter is opened has no effect.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Sep-2013 10:44:15   

But creating an adapter doesn't open a connection yet. If you set it before the first action is done/connection is opened, it will take effect.

I recon the connection is already open?

Frans Bouma | Lead developer LLBLGen Pro
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 10-Sep-2013 11:38:31   

Yes, the adapter is already opened when I get it wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Sep-2013 14:33:25   

acl wrote:

Yes, the adapter is already opened when I get it wink

Adapter or its connection, these are two different things: creating a dataaccessadapter instance doesn't open a connection, hence my question: there's no adapter 'open'.

Frans Bouma | Lead developer LLBLGen Pro
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 11-Sep-2013 07:53:27   

I meant the connection, sorry

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Sep-2013 13:43:15   

Then it's indeed only possible to do what you want by starting a short transaction. You could create a default ActionQuery for this, but it's not supported by the framework.

Frans Bouma | Lead developer LLBLGen Pro
acl
User
Posts: 91
Joined: 28-Mar-2012
# Posted on: 12-Sep-2013 09:24:44   

ok, thanks!