Rollback timeout ???

M

Mike

I have a vb.net application. Using ado.net, I create/open a connection,
create a transaction object, and go through a loop. In each interation of
the loop, I create a SqlClient.SqlCommand (using this transaction object)
and perform a cmd.ExecuteNonQuery using a SQL Update statement. After
everything is said and done, I have transaction object with about 12,000
updates in it. If I try a trans.Rollback, I get a SqlClient.SqlException
that is a timeout exception. How does a rollback timeout ? The
SqlClient.SqlTransaction object does not have a timeout property. Anyone
know where this comes from ?

Thanks,
Mike
 
A

Angel Saenz-Badillos[MS]

I actually like and would recommend using the tsql Begin Transaction instead
of the API, this allows you to set the timeout on the command very clearly.
Some things to keep in mind:

Don't mix the two, it will get confusing.
Make _sure_ (by using a finally clause) that your transaction is completed
before closing the connection. Otherwise you will leak the transaction for
the ammount of time the connection remains in the pool.

As to setting the transaction timeout period for the BeginTransaction API...
We hardcode this value to the Connection Timeout (default 15 seconds) so
this could be used as a workarround.

--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET: http://weblogs.asp.net/angelsb/




Miha Markic said:
Hi Mike,

You are right - you can't set rollback timeout (this is a "feature").
Instead you can issue your own "rollback transaction" command.
See this thread:
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#2c1324abac6a646b

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Mike said:
I have a vb.net application. Using ado.net, I create/open a connection,
create a transaction object, and go through a loop. In each interation of
the loop, I create a SqlClient.SqlCommand (using this transaction object)
and perform a cmd.ExecuteNonQuery using a SQL Update statement. After
everything is said and done, I have transaction object with about 12,000
updates in it. If I try a trans.Rollback, I get a SqlClient.SqlException
that is a timeout exception. How does a rollback timeout ? The
SqlClient.SqlTransaction object does not have a timeout property. Anyone
know where this comes from ?

Thanks,
Mike
 
M

Mike

Hi Miha,
Perfect answer, works like expected now. Do you know if this could happen
with a .Commit also ?

Mike

Miha Markic said:
Hi Mike,

You are right - you can't set rollback timeout (this is a "feature").
Instead you can issue your own "rollback transaction" command.
See this thread:
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#2c1324abac6a646b

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Mike said:
I have a vb.net application. Using ado.net, I create/open a connection,
create a transaction object, and go through a loop. In each interation of
the loop, I create a SqlClient.SqlCommand (using this transaction object)
and perform a cmd.ExecuteNonQuery using a SQL Update statement. After
everything is said and done, I have transaction object with about 12,000
updates in it. If I try a trans.Rollback, I get a SqlClient.SqlException
that is a timeout exception. How does a rollback timeout ? The
SqlClient.SqlTransaction object does not have a timeout property. Anyone
know where this comes from ?

Thanks,
Mike
 
M

Mike

I'm not sure how I would "make sure the transaction is completed". I know my
updating is done, and I have done a oTran.Commit or a Command object
"Rollback transaction". Are you advocating doing a oTran.Dispose() before I
do a oConn.Close() ?

Thanks,
Mike

Angel Saenz-Badillos said:
I actually like and would recommend using the tsql Begin Transaction instead
of the API, this allows you to set the timeout on the command very clearly.
Some things to keep in mind:

Don't mix the two, it will get confusing.
Make _sure_ (by using a finally clause) that your transaction is completed
before closing the connection. Otherwise you will leak the transaction for
the ammount of time the connection remains in the pool.

As to setting the transaction timeout period for the BeginTransaction API...
We hardcode this value to the Connection Timeout (default 15 seconds) so
this could be used as a workarround.

--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET: http://weblogs.asp.net/angelsb/




Miha Markic said:
Hi Mike,

You are right - you can't set rollback timeout (this is a "feature").
Instead you can issue your own "rollback transaction" command.
See this thread:
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#2c1324abac6a646b
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Mike said:
I have a vb.net application. Using ado.net, I create/open a connection,
create a transaction object, and go through a loop. In each interation of
the loop, I create a SqlClient.SqlCommand (using this transaction object)
and perform a cmd.ExecuteNonQuery using a SQL Update statement. After
everything is said and done, I have transaction object with about 12,000
updates in it. If I try a trans.Rollback, I get a SqlClient.SqlException
that is a timeout exception. How does a rollback timeout ? The
SqlClient.SqlTransaction object does not have a timeout property. Anyone
know where this comes from ?

Thanks,
Mike
 
M

Miha Markic [MVP C#]

Hi Mike,

Sure, and I do agree with Angel on the point "not mix them".

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Mike said:
Hi Miha,
Perfect answer, works like expected now. Do you know if this could happen
with a .Commit also ?

Mike

Miha Markic said:
Hi Mike,

You are right - you can't set rollback timeout (this is a "feature").
Instead you can issue your own "rollback transaction" command.
See this thread:
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#2c1324abac6a646b

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Mike said:
I have a vb.net application. Using ado.net, I create/open a connection,
create a transaction object, and go through a loop. In each interation of
the loop, I create a SqlClient.SqlCommand (using this transaction object)
and perform a cmd.ExecuteNonQuery using a SQL Update statement. After
everything is said and done, I have transaction object with about
12,000
updates in it. If I try a trans.Rollback, I get a
SqlClient.SqlException
that is a timeout exception. How does a rollback timeout ? The
SqlClient.SqlTransaction object does not have a timeout property.
Anyone
know where this comes from ?

Thanks,
Mike
 
A

Angel Saenz-Badillos[MS]

Let me explain the problem and the solution will be clearer.

Using the api:
When you call the BeginTransaction API method we will mark this connection
as having a transaction.
When you call the Transaction.Commit or Rollback we will unmark the
connection.
If you close a connection that is marked as having a transaction active we
will do a roundtrip to the server to reset the connection,

Not using the api:
When you execute a command "Begin Tran", "Commit tran" or "rollback tran"
we do not mark the connection.( this is because we do not parse command text
and have no idea that you are doing this).
If you start a transaction with "Begin Tran" and you close the connection
without calling commit or rollback _the transaction will continue to be
active_ until the next time the connection does a roundtrip to the server.
The connection can be idle and locking resources for up to 8 minutes in the
pool! Make sure that your code guarantees the transaction commit or rollback
if an exception is thrown. I find the following TSQL helpfull : "IF
@@TRANCOUNT > 0 ROLLBACK TRAN"

If you mix both api and TSQL transactions you will be forcing extra
roundtrips to the server, effectively negating the benefits of pooling.
Don't do this!

--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET: http://weblogs.asp.net/angelsb/




Mike said:
I'm not sure how I would "make sure the transaction is completed". I know my
updating is done, and I have done a oTran.Commit or a Command object
"Rollback transaction". Are you advocating doing a oTran.Dispose() before I
do a oConn.Close() ?

Thanks,
Mike

Angel Saenz-Badillos said:
I actually like and would recommend using the tsql Begin Transaction instead
of the API, this allows you to set the timeout on the command very clearly.
Some things to keep in mind:

Don't mix the two, it will get confusing.
Make _sure_ (by using a finally clause) that your transaction is completed
before closing the connection. Otherwise you will leak the transaction for
the ammount of time the connection remains in the pool.

As to setting the transaction timeout period for the BeginTransaction API...
We hardcode this value to the Connection Timeout (default 15 seconds) so
this could be used as a workarround.

--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET: http://weblogs.asp.net/angelsb/




Miha Markic said:
Hi Mike,

You are right - you can't set rollback timeout (this is a "feature").
Instead you can issue your own "rollback transaction" command.
See this thread:
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#2c1324abac6a646b
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

I have a vb.net application. Using ado.net, I create/open a connection,
create a transaction object, and go through a loop. In each
interation
of
the loop, I create a SqlClient.SqlCommand (using this transaction object)
and perform a cmd.ExecuteNonQuery using a SQL Update statement. After
everything is said and done, I have transaction object with about 12,000
updates in it. If I try a trans.Rollback, I get a SqlClient.SqlException
that is a timeout exception. How does a rollback timeout ? The
SqlClient.SqlTransaction object does not have a timeout property. Anyone
know where this comes from ?

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top