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/ [quoted text, click to view] "Mike" <mberger@skypoint.com> wrote in message
news:i_WdnfFjcMpOf2LcRVnyhA@skypoint.com...
> 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[MS]" <angelsa@online.microsoft.com> wrote in message
> news:eTTrJRJCFHA.2076@TK2MSFTNGP15.phx.gbl...
> > 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 [MVP C#]" <miha at rthand com> wrote in message
> > news:eRuV9dDCFHA.1392@tk2msftngp13.phx.gbl...
> > > 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/microsoft.public.dotnet.framework.adonet/browse_frm/thread/da5daf08504d40fd/2c1324abac6a646b?q=Rollback+timeout+group:*adonet*&_done=%2Fgroups%3Fas_q%3DRollback+timeout%26safe%3Dimages%26as_ugroup%3D*adonet*%26lr%3D%26hl%3Den%26&_doneTitle=Back+to+Search&&d#2c1324abac6a646b
> > >
> > > --
> > > Miha Markic [MVP C#] - RightHand .NET consulting & development
> > > SLODUG - Slovene Developer Users Group
> > >
www.rthand.com > > >
> > > "Mike" <mberger@skypoint.com> wrote in message
> > > news:O7edncokL80bemPcRVnygw@skypoint.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
> > > >
> > > >
> > >
> > >
> >
> >
>
>