By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Testing Transaction Commit and Rollback in C# ASP.Net

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.