By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,274 Members | 2,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,274 IT Pros & Developers. It's quick & easy.

database access pattern

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.