Re: Using Transaction scope
- From: changliw@xxxxxxxxxxxxxxxxxxxx (Charles Wang[MSFT])
- Date: Thu, 02 Nov 2006 07:24:11 GMT
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
.
- References:
- Using Transaction scope
- From: AnikSol
- RE: Using Transaction scope
- From: Charles Wang[MSFT]
- Re: Using Transaction scope
- From: AnikSol
- Using Transaction scope
- Prev by Date: Re: Using Transaction scope
- Next by Date: RE: Cannot Create a Relationship
- Previous by thread: Re: Using Transaction scope
- Next by thread: Re: Using Transaction scope
- Index(es):
Relevant Pages
|