470,602 Members | 1,562 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

Testing Transaction Commit and Rollback in C# ASP.Net

Hi,

I am just wondering how do we test the transaction's Commit and Rollback?
How do we simulate a situation to let the transaction fail then Rollback?
Thanks for help.

Jason
Nov 17 '05 #1
1 9968
Hello Jason,

U can do it with transaction resource managers (resources that can be enlisted
in transaction), for example database
See this CodeSnippet

string connectionString = "...";
IDbConnection connection = new SqlConnection(connectionString);
connection.Open();
IDbCommand command = new SqlCommand();
command.Connection = connection;

IDbTransaction transaction;
transaction = connection.BeginTransaction(); //Enlisting database
command.Transaction = transaction;
try
{
/* Interact with database here, then commit the transaction */
transaction.Commit();
}
catch
{
transaction.Rollback(); //Abort transaction
}
finally
{
connection.Close();
}
JH> I am just wondering how do we test the transaction's Commit and
JH> Rollback? How do we simulate a situation to let the transaction fail
JH> then Rollback? Thanks for help.

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by DP | last post: by
1 post views Thread by Avanish Pandey | last post: by
2 posts views Thread by Alexander Korovyev | last post: by
3 posts views Thread by joshsackett | last post: by
1 post views Thread by Matik | last post: by
1 post views Thread by cricketweb | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.