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. 4 1834
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**@discussio ns.microsoft.co m> wrote in message
news:30******** *************** ***********@mic rosoft.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.
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#)
------------------------------------------------------------------------
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
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******** ******@TK2MSFTN GP15.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 application and
will store events that happen in the database (These events happen randomly
without pattern, between 10-50 a day) .
There are a number of situations where the database is accessed.
|
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
|
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, when
should I it close it -- after the execution of the each command to the
database? If leaving open, what impacts does it have. Imagining that
it is one connection to the database.
Thanks,
mescano
|
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), and not the client.
I think the best way to do this is to expose data layer objects using
Remoting to the client.
This sounds almost like a design pattern to me, but I can't seem to find
|
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. Enterprise version use
Centralized Web Service as Database. Which is the easiest way to handle this?
I have too many classes have data access.
I can create following classes, How could I use Interface or other ways to
call right DB?
class1
| |
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 point in time. I have studied some
examples I found on the internet, and am now trying to build my own from
scratch.
I have made a default table class (DB_Table), a default validation class
(Validator) which is an object inside DB_Table and my...
|
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 the messaging pattern?
Thank you for any help.
David
|
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. The pattern that
best describes this is here:
http://martinfowler.com/eaaCatalog/serviceStub.html
I have found http://qualitylabs.org/pdbseed/, which helps with
|
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 Apache on
my machine. I'm a beginner and I really don't understand how to
proceed. My biggest problem is how to connect to the database on
remote mysql server ? Does php allow this kind of thing ? I'm
interested in a web interface on my machine...
|
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...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |