• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1296
  • Last Modified:

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

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
prasadrao007
Asked:
prasadrao007
1 Solution
 
kraffayCommented:
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
 
prasadrao007Author Commented:
I didnt know that i had to close the question. Sorry abt that..
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now