473,385 Members | 1,275 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,385 software developers and data experts.

proper way to abstract db access?

Hello all,
can someone possibly clear up what the 'proper' way to abstract DB access
is? (Using C#, though it shouldnt matter)

For example my asp page calls a web service that has an authenticate method
that uses a username/pass table in a DB..

I set up a DB class that connects to the DB and has a public OleConnection.
The webservice builds the olecommand and runs it against that public
OleConnection, but that somehow seems wrong. Sticking every possible
olecommand in my db connection class also doesnt make any sense.

So whats the right layout? Im trying to build it so that its easy to
implement connection pooling and caching later if i need to, and so I can
easily port to Oracle/MS SQL.
Nov 19 '05 #1
3 1285
You can implement a webservice or ATL to access database. But INMH proper
way is using a Service Oriented approach. My advice u to implement it using
Microsoft .NET Remoting technologies and a server activated approach and
singleton pattern. You can easily built up a caching mechanism on it.

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

<japhar81> wrote in message news:qb********************@giganews.com...
Hello all,
can someone possibly clear up what the 'proper' way to abstract DB access
is? (Using C#, though it shouldnt matter)

For example my asp page calls a web service that has an authenticate
method that uses a username/pass table in a DB..

I set up a DB class that connects to the DB and has a public
OleConnection. The webservice builds the olecommand and runs it against
that public OleConnection, but that somehow seems wrong. Sticking every
possible olecommand in my db connection class also doesnt make any sense.

So whats the right layout? Im trying to build it so that its easy to
implement connection pooling and caching later if i need to, and so I can
easily port to Oracle/MS SQL.

Nov 19 '05 #2
You might want to look at the source code and examples for the data
access block in Enterprise Library [1].

[1]
http://www.microsoft.com/downloads/d...displaylang=en

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 1 May 2005 00:36:49 -0400, <japhar81> wrote:
Hello all,
can someone possibly clear up what the 'proper' way to abstract DB access
is? (Using C#, though it shouldnt matter)

For example my asp page calls a web service that has an authenticate method
that uses a username/pass table in a DB..

I set up a DB class that connects to the DB and has a public OleConnection.
The webservice builds the olecommand and runs it against that public
OleConnection, but that somehow seems wrong. Sticking every possible
olecommand in my db connection class also doesnt make any sense.

So whats the right layout? Im trying to build it so that its easy to
implement connection pooling and caching later if i need to, and so I can
easily port to Oracle/MS SQL.


Nov 19 '05 #3
This is a hard question to answer. You could code everything in every single
method, but as you might suspect, this ends up with a lot of duplicated code.
Even if every method ultimately does a different SQL operation, there is
the common connection setup and teardown. So you think about ways to abstract
and refactor this common code. Scott mentioned the MS DataAccess Block. That
or an idea like that (personally I don't use it, as I have my own that I
prefer over it) is a good first start. If that's sufficient, then great.
But when if the SQL starts to be duplicated method by method... Well, then
that's when you start to look at factoring out that bit too. This is when
you look to move all of your data access out form the page and/or webservice
and put it all into its own assembly. This then hides the data access behind
an API that just returns you the data. You let the data access code sort
out the details. Once you've done this, then that's an opportunity to cache
data in the data access layer (if possible/appropriate), as the UI/service
code doesn't know (or care) how the data was acquired (BTW, I'm using data
access layer loosly here, as some people have very specific connotations
to that term (DAL), but it is certainly related). Once you've factored out
the work into a seperate location, then it's much easer to reuse that work.

Anyway, there's nothing that says you have to build your systems like this...
It's just something to consider.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello all,
can someone possibly clear up what the 'proper' way to abstract DB
access
is? (Using C#, though it shouldnt matter)
For example my asp page calls a web service that has an authenticate
method that uses a username/pass table in a DB..

I set up a DB class that connects to the DB and has a public
OleConnection. The webservice builds the olecommand and runs it
against that public OleConnection, but that somehow seems wrong.
Sticking every possible olecommand in my db connection class also
doesnt make any sense.

So whats the right layout? Im trying to build it so that its easy to
implement connection pooling and caching later if i need to, and so I
can easily port to Oracle/MS SQL.


Nov 19 '05 #4

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

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
1
by: f00sion | last post by:
I found a good tutorial of how to supply the objects without having the implementation files on the client. This was working great until I realized that I couldnt use any constructors with server...
4
by: Tony Johansson | last post by:
Hello! Assume you have an abstract class called Body and a derived class called cylinder. When you have an abstract class you can't instansiate an object. As you can see in the abstract class...
9
by: Christian Christmann | last post by:
Hi, I've a class Handler which contains a STL list std::list<Abstract*> mAbstract; which is storing elements of the abstract class Abstract. Further this class has a getElement function to...
3
by: Daniel Billingsley | last post by:
The base class obviously can't know anything about a class which inherits from it, but is it acceptable to have a base class method which will be given information from an inherited class? For...
0
by: Benjamin | last post by:
Hi, I am unable to access all properties and methods in a COM .DLL that I have. The properties and methods exposed by the .dll all appear as "abstract" when I view them in the Object Browser. ...
7
by: tron.thomas | last post by:
Please consider the following code: class Abstract { public: virtual ~Abstract() {} virtual void Method() = 0; }; class Concrete : public virtual Abstract
6
by: bwaichu | last post by:
Can someone help me out here? This is one of those areas of C that I am fuzzy on. I'm not quite sure when I should use volatile. If you could provide an example, that would help out a lot. I...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.