Solved

Creating ADO.NET Transaction in N-Tier architecture in C#

Posted on 2006-11-22
3
1,177 Views
Last Modified: 2008-02-07
How do we create ADO.NET Transaction in N-Tier architecture in C#

Like what goes in User Interface layer , what in the middle tier...

My idea is two have sql statements like calling in 2 stored procedures separtely and rollback the total transaction if any one of the stored procedure fails...

I kind of know what to do with only user interface layer but i dont know how to do in N-tier architecture..

Please give me a example of how it can be done this way...

Thanks,
prasad

0
Comment
Question by:prasadrao007
3 Comments
 
LVL 9

Accepted Solution

by:
kraffay earned 500 total points
ID: 17998152
1.  Get the free Enterprise Library from Microsoft (http://msdn.microsoft.com/library/?url=/library/en-us/dnpag2/html/EntLib2.asp).  This will give you the data layer.

2.  Implement transactions in the middle tier per the quick start examples, like so (I am using inline sql here, but the EL works fine with SPs):

Database _db = DatabaseFactory.CreateDatabase("LocalSQLServer");
using (DbConnection connection = _db.CreateConnection())
        {

            connection.Open();
            DbTransaction transaction = connection.BeginTransaction();

            try
            {
                String SQL;

                SQL = "UPDATE CategoryLog" +
                        " SET CategoryID = " + CategoryID +
                        " WHERE CategoryLogID =" + CategoryLogID;

                _db.ExecuteNonQuery(CommandType.Text, SQL);


                SQL = "UPDATE Log" +
                        " SET EventID = " + txtEventID.Text + "," +
                        " Severity = '" + txtSeverity.Text + "'," +
                        " MachineName = '" + txtMachineName.Text + "'," +
                        " ProcessID = " + txtProcessID.Text +
                        " WHERE LogID = " + LogID;

                _db.ExecuteNonQuery(CommandType.Text, SQL);
                return true;
            }
            catch
            {
                transaction.Rollback();
                return false;
            }
0
 

Author Comment

by:prasadrao007
ID: 18198202
I didnt know that i had to close the question. Sorry abt that..
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question