Solved

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

Posted on 2006-11-22
3
1,104 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
Comment Utility
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
Comment Utility
I didnt know that i had to close the question. Sorry abt that..
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Can't create users table in existing DB 16 60
Hangfire / asp.net sample 3 27
Asp.net mvc entity issue 6 19
Hidden Field Value 10 34
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now