Solved

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

Posted on 2006-11-22
3
1,158 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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