Solved

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

Posted on 2006-11-22
3
1,136 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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