Problem solve Get help with specific problems with your technologies, process and projects.

Can transaction failure event handler be implemented on a Web-based app?

Can transaction failure event handler be implemented on a Web-based application in which either records will be inserted or updated in about 10 tables?
To handle transactions you have to use ADO.NET features. It's not a matter of Web-based or Windows-based applications. ADO.NET provides a BeginTransaction() method for all objects implementing IDbConnection (such as OleDbConnection and SqlConnection). This method returns an IDbTransaction object you can use to commit or rollback an entire operation. The typical usage pattern is:

IDbConnection cn = new SqlConnection("your connection string");
IDbTransaction trans = cn.BeginTransaction();
	//try to update/insert everything using cn as the connection
	//Use cn.CreateCommand() to get IDbCommand to execute queries.

Using the ADO.NET interfaces instead of the SqlClient classes directly, makes it far easier to port this code later to another DB engine. In the case shown above, only the first line that creates the new SqlConnection would need to be changed. Better yet, you could use an abstract factory so you have a single point of change in the future.

This was last published in May 2003

Dig Deeper on C# programming language

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.