Re: Using Transaction scope

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,
I am afraid not. If a connection is timeout and the transaction has been
running but not been committed, SQL Server will automatically rollback the
operations at the end. If your code snippet is like this:
SqlConnection cn = new SqlConnection("data
source=myserver;initial catalog=testdb;integrated security=SSPI;Connection
Timeout=15");
cn.Open();
SqlCommand cmd = new SqlCommand("select * into table1 from
table2 where id = 70", cn); //Assuming that it takes about 50seconds to be
accomplished
SqlTransaction trans = cn.BeginTransaction();
cmd.Transaction = trans;
try
{
cmd.ExecuteNonQuery();
trans.Commit();
textBox1.Text += "\r\nCommit Transaction.";
}
catch (Exception e1)
{
trans.Rollback();
textBox1.Text += "\r\nRollback Transaction:" + e1.Message;
}
finally
{
cn.Close();
textBox1.Text += "\r\nClosed.";
}
when the timeout comes out, trans.Rollback() will fail with an exception
but SQL Server will automatically rollback the transaction at the server
side since it cannot receive the commit command from the client. If an
application does not use trasaction, some operations may not be able to
automatically rollback when the connection is disconnected.

I am not clear what the situation that you are encountering. If this issue
persists, could you please mail me (changliw@xxxxxxxxxxxxx) a test database
backup file and your code snippet for further research?

If you have any other questions or concerns, please feel free to let me
know. It is my pleasure to be of assistance.

Charles Wang
Microsoft Online Community Support





.



Relevant Pages

  • Re: Locking and Delay in a Bottleneck
    ... Invoices, Purchasing, etc) are generating a journal voucher accompanying ... the saving transaction, this journal voucher is having a header table ... number in a table whereupon you commit. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.sqlserver.programming)
  • Re: Locking and Delay in a Bottleneck
    ... requirement that there be no gaps. ... the saving transaction, this journal voucher is having a header table ... number in a table whereupon you commit. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL 7 vs. 2000 issue -trigger and nulls
    ... >We're having trouble with a trigger updating some tables. ... course be locked by the current transaction, ... locking data and updating rows when the COMMIT inside the trigger is ... I seriously hope that SQL Server 7.0 simply disregarded these two ...
    (microsoft.public.sqlserver.mseq)
  • Re: Few confusing things about transactions
    ... abort the transaction? ... COMMIT and ROLLBACK. ... COMMIT is the normal flow. ... Error handling in SQL Server ...
    (microsoft.public.sqlserver.programming)
  • Re: Multi-Database Transactions
    ... SQL Server has supported the concept of cross-database (or even cross ... "2-phase commit". ... > I've been looking into adding transaction capabilities into my object ... people were talking about data _sources_ instead of databases. ...
    (microsoft.public.dotnet.framework.adonet)