473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

database access pattern

How does everyone design the database access layer in an asp.net application?
Two options that come to mind is:

1. create a database class and instanciate it as needed, local to a function
or
2. Provide database access in a base class from which all objects that need
db access will inherit from.

#1 seems wasteful for application that do frequent but light db access.
Option #2 seems even more wasteful, because it adds overhead to the
inheriting class creation, whether or not that class will do db access.

The third option that I have been thinking about is a modification of 1, but
make it as a singleton. Would that help any, or will it become a bottleneck?

I'm just looking for pointers on best practives on implementing the database
layer. I found some in MSDN, but they were more implementation related,
rather than design related. I'd like to cut down on object creation, while at
the same time keep throughput as high as possible. Creating a database class
is usually expensive, since it involves retrieving a connection string,
setting up multiple objects, etc...

any ideas would be appreciated.

Jan 19 '06 #1
4 1811
Definitely #1 and I do not like your singleton idea. Really you only need
one instance of a DAL so a singleton would work well. I would not think you
would want the data access to reside in the base for all your classes. Part
of design is to isolate the data access part into its own area, then have
the other classes call methods that returns specific pieces of information.

"Val P" <Va**@discussions.microsoft.com> wrote in message
news:30**********************************@microsof t.com...
How does everyone design the database access layer in an asp.net
application?
Two options that come to mind is:

1. create a database class and instanciate it as needed, local to a
function
or
2. Provide database access in a base class from which all objects that
need
db access will inherit from.

#1 seems wasteful for application that do frequent but light db access.
Option #2 seems even more wasteful, because it adds overhead to the
inheriting class creation, whether or not that class will do db access.

The third option that I have been thinking about is a modification of 1,
but
make it as a singleton. Would that help any, or will it become a
bottleneck?

I'm just looking for pointers on best practives on implementing the
database
layer. I found some in MSDN, but they were more implementation related,
rather than design related. I'd like to cut down on object creation, while
at
the same time keep throughput as high as possible. Creating a database
class
is usually expensive, since it involves retrieving a connection string,
setting up multiple objects, etc...

any ideas would be appreciated.


Jan 20 '06 #2
Val P wrote:
How does everyone design the database access layer in an asp.net
application? Two options that come to mind is:

1. create a database class and instanciate it as needed, local to a
function or
2. Provide database access in a base class from which all objects
that need db access will inherit from.

#1 seems wasteful for application that do frequent but light db
access. Option #2 seems even more wasteful, because it adds overhead
to the inheriting class creation, whether or not that class will do
db access.

The third option that I have been thinking about is a modification of
1, but make it as a singleton. Would that help any, or will it become
a bottleneck?

I'm just looking for pointers on best practives on implementing the
database layer. I found some in MSDN, but they were more
implementation related, rather than design related. I'd like to cut
down on object creation, while at the same time keep throughput as
high as possible. Creating a database class is usually expensive,
since it involves retrieving a connection string, setting up multiple
objects, etc...


object creation is very very fast in .NET, so #1 isn't a waste. Never
go for 'singletons' for dataaccess, it will likely limit the
scalability of your application as singletons should be either
immutable OR have locking functionality, which slows down application
flow.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jan 20 '06 #3
ValP.

Be aware that an ASPNET application is stateless and belongs to all clients.

It means that any data that you use static/shared will be shared by all
clients.

Therefore in my opinion is the best design that you get all (major)
datahandling in a static/shared class.

However keep the data itself (except never changing data) completely apart
in classes, which you have to instance at the load of a webpage.

There are other options, in my opinion very complex.
The major problem is that you never know when a user disconnect from your
application.

I hope this helps,

Cor
Jan 20 '06 #4
Ops, did not think about the "static" issue when I commented on the use of
singleton. For a desktop app singleton would work, but not in the web app
(or rather should be avoided).

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eG**************@TK2MSFTNGP15.phx.gbl...
ValP.

Be aware that an ASPNET application is stateless and belongs to all
clients.

It means that any data that you use static/shared will be shared by all
clients.

Therefore in my opinion is the best design that you get all (major)
datahandling in a static/shared class.

However keep the data itself (except never changing data) completely apart
in classes, which you have to instance at the load of a webpage.

There are other options, in my opinion very complex.
The major problem is that you never know when a user disconnect from your
application.

I hope this helps,

Cor

Jan 20 '06 #5

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

Similar topics

4
by: Macca | last post by:
Hi, I have an windows forms application that accesses a SQL database I have a few questions as to connecting to the database. This application will run 24 hours a day. It is a monitoring...
5
by: Gustavo De la Espriella | last post by:
Hi, What's a good way to make an application automatically choose between SQLClient, ODBC, Oracle and OleDB depending on user's choice? Thanks, Gustavo De la Espriella
4
by: mescano | last post by:
I am currently implementing a singleton pattern for accessing a database. Is it advisable to close the connection to the database at all -- thus leaving it open or should it be closed. If closed,...
2
by: | last post by:
Dear Groups, I am trying to develop a simple client <-> server application where (for database security reasons) the server only has access to the centralised database (and a file repository),...
3
by: Qingdong Z. | last post by:
I know this is a silly question, but I am looking for the best way. I build a windows application with standard version and enterprise version. Standard version use local SQL/Access as database....
22
by: amygdala | last post by:
Hi, I'm trying to grasp OOP to build an interface using class objects that lets me access database tables easily. You have probably seen this before, or maybe even built it yourself at some...
8
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
Now we have some trouble to directly access to SQL Server database. I would like to know if there is a special protocol in the communication between SQL SERVER client and databse system. What is...
9
by: Daniel | last post by:
Hello, I'm writing an application that interacts with a database. As I think about how to write the unittests, I want them to be able to run without actually having to access a live database. ...
25
by: pereges | last post by:
Hello, I'm trying to build a database driven website for a library management system. The database is stored on a remote server which all of my team mates can access. I've installed MySQL, PHP and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.