473,722 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle transactions at Business LogicLayer level

I am working on an N-tier application using following components:
1. Data Access Layer using DLINQ which consists of Data Context class
and Table Mapping classes.
2. Business Logic Layer.
3. Presentation Layer (normal ASP.NET pages)
The problem is that I have to handle database transactions which can
span multiple tables. So where should I place the transaction code. I
think I should do it in BLL. But how do I control the transaction at
BLL layer level. Please suggest.

Thanks in advance.
- param
Nov 10 '08 #1
3 7096
Something that I have always tried to do is create all of the sql
transactions in the stored procedures of the database and then working with
the c#/vb code would be a lot easier. You wouldn't have to be always making
inserts to multiple tables all the time in the application code since thats
not the applications job anyways. I am just getting into the entity model
framework and it looks pretty good especially when you can write only 3
lines of vb code and insert values into about 30 different tables with 100%
success rate and pretty fast as well. I of course didn't use that in a real
life application, it was just a junk test that I created to see how much
entity framework would make my life easier or more complicated.
"psycho" <pa***********@ gmail.comwrote in message
news:17******** *************** ***********@f40 g2000pri.google groups.com...
>I am working on an N-tier application using following components:
1. Data Access Layer using DLINQ which consists of Data Context class
and Table Mapping classes.
2. Business Logic Layer.
3. Presentation Layer (normal ASP.NET pages)
The problem is that I have to handle database transactions which can
span multiple tables. So where should I place the transaction code. I
think I should do it in BLL. But how do I control the transaction at
BLL layer level. Please suggest.

Thanks in advance.
- param

Nov 10 '08 #2


I don't know if there is a right or wrong answer to this....However , I will
give my opinion.

First, are you using Sql Server (or another RDBMS)?

......

Option1:
With Sql Server 2000 and 2005, you can handle multiple table
transactions inside a usp (user stored procedure). You can accomplish this
through alot of scalar values OR using XML.
With 2008, you can accomplish this using
http://channel9.msdn.com/posts/ashis...ed-parameters/
Table Valued Parameters. I have experience with 2000/2005 and am only
getting into 2008 with this particuliar need.
You would handle the Transactions at the USP level.

Here is the most basic example of a usp transaction on 2 updates:
http://groups.google.com/group/micro...4?dmode=source
THis isn't a great example, but has the nuts/bolts of the logic.
Actually, I would use the:
dbo.uspEmployee DepartmentJobTi tleUpdate
from the next URL I mention immediately below as an example.

Option2:
https://www.microsoft.com/communitie...r=US&sloc=&p=1

You can put the transaction code in DotNet code. The above link shows some
examples of that I coded up. I didn't get alot of feedback on the post fyi.
But at least you have the code examples.
The example uses 3 tables, Emp, Dept, JobTitle.

Now, we have to discuss what you mean and I mean by BAL and DAL. Some
people have the BAL call "Helpers" and consider that the DAL. Example. The
BAL calling (directly) the SqlHelper class of the DAAB (circa 4-5 years
ago).

Some people (like me) have a DAL layer, and uses the SqlHelper or
EnterpriseLibra ry.Data ~as helpers.....and not "instead of" the DAL.
You can see a code example of this here:
http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!140.entry
(Also check my 1.1 version of that same article at
http://sholliday.spaces.live.com/Blog/ or
http://sholliday.spaces.live.com/feed.rss )

If you're using a true DAL (and not simply (and errantly in my opinion)
calling a Helper class from your BAL).......then you ~can code up the
transactions in the DAL.

If I were talking to 2 different databases, I would use this approach. I
would pick on of the DAL (DotNet) syntaxes from the URL (listed underneath
of Option2 above) and use that.

If I were using a non SQL Server RDBMS like Oracle, I would use this
approach as well...since my experience with Oracle and Xml was not a found
one.

............... ....

So my nutshell advice:
1. If you're using Sql Server, I would try XML to pass all your data down
and use usp's (BEGIN TRAN, COMMIT TRAN, ROLLBACK TRAN). << My opinion.
2. If you're using multiple databases or something non sql
server.......th en (A) Make sure you have an actual DAL layer defined (and
are NOT simply using the "Helper" classes like SqlHelper or
EnterpriseLibra ry.Data)....... .and then put in DotNet transactions. The URL
(mentioned above under Option 2) should provide the syntax(es) for that.

............... .

Good luck.

"psycho" <pa***********@ gmail.comwrote in message
news:17******** *************** ***********@f40 g2000pri.google groups.com...
>I am working on an N-tier application using following components:
1. Data Access Layer using DLINQ which consists of Data Context class
and Table Mapping classes.
2. Business Logic Layer.
3. Presentation Layer (normal ASP.NET pages)
The problem is that I have to handle database transactions which can
span multiple tables. So where should I place the transaction code. I
think I should do it in BLL. But how do I control the transaction at
BLL layer level. Please suggest.

Thanks in advance.
- param

Nov 10 '08 #3
I have found a way to manage transactions using TransactionScop e.

using (TransactionSco pe scope = new TransactionScop e
(TransactionSco peOption.Requir esNew))
{
User.Save();
UserGroup.Save( );

scope.Complete( );

}

Nov 12 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9019
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the start of the transaction aren't visible to those later on in that transaction (using a different cursor). Attached is a simplified example (the except's are a bit blunt, I know) of what I'm trying to do. In reality, the different cursors are...
0
3323
by: Heikki Tuuri | last post by:
Hi! Many people have complained over years that Borland's dbExpress driver does not work with MySQL and transactions, because it disconnects from mysqld after each SQL statement. The postings below suggests that this problem might now be fixed by Borland. Best regards, Heikki Tuuri
2
3051
by: Indiana Epilepsy and Child Neurology | last post by:
Before asking this questions I've spent literally _years_ reading (Meyer, Stroustrup, Holub), googling, asking more general design questions, and just plain thinking about it. I am truly unable to figure out what would be a "proper" OO design (in C++) for this. There may be alternatives to writing my own ODBC handle classes, and I may be interested in them, but I'd like to pursue this particular problem, if for no other reason than to...
2
1519
by: John | last post by:
Hi Is it possible to handle errors at form level that are not caught by the error handlers within the form subs? Regards
1
1185
by: hazz | last post by:
I have a Customer table and an Inquiry table. I have a few fields in the Customer table which I want to include when I instantiate and hydrate a business object which I use for business logic and whose properties update the corresponding table(s) column values at the end of the method/event. The Inquiry table has columns Score,Status, DateXXX, DateYYY, etc. CustomerId is a foreign key in Inquiry.
3
3439
by: Dave Wurtz | last post by:
All, Does anyone have ideas how they have implemented field (property) level security? I want to handle this from the business object level, not the database level. Is it best to have a security checking method that gets called in the property and throws an exception? If there are several "fields" that are being accessed multiple times, does it hurt from a performance perspective to have these exceptions thrown all of the time? ...
0
2995
by: OMNI GROUP | last post by:
OMNI GROUP tgugger@sbcglobal.net 419-537-9447 ENTRY LEVEL/ JAVA or C/ IMMEDIATE/ IN
1
942
by: NH | last post by:
Is it best practice to handle transactions in ADO.Net or in the database level within stored procedures?
12
2041
by: Rami | last post by:
I have some requirement for an automated payment system. The system has four machines setup as follows: 1- Two machines have a clustered database. 2- Two machines have a .net business logic component that will handle payment transactions with certain external component (Payment Gateway) My query is regarding transaction handling inside the business logic component. Because this component is running on two machines and these two...
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.