Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

DAL...should the methods be static?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
H - 22 Mar 2008 13:18 GMT
In my BusinessLogicLayer, there are many places where I call the
DataAccessLayer.

Is it better to have static methods in my DAL that are lock()'ed and
called directly from my BLL (thus the CLR takes care of concurrency)
or should I have public methods and create an instance of my DAL each
time it is used (thus let SQL Server take care of concurrency)?

adv-thanks-ance...
Just Me - 22 Mar 2008 17:43 GMT
The only reason you need to lock them is if they are making use of a static
variable which you should avoid at all costs.

I have used static methods extensively in my DAL without problems in a multi
user environment.

> In my BusinessLogicLayer, there are many places where I call the
> DataAccessLayer.
[quoted text clipped - 5 lines]
>
> adv-thanks-ance...
Mark Rae [MVP] - 22 Mar 2008 19:05 GMT
> I have used static methods extensively in my DAL without problems in a
> multi user environment.

Me too.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

HelloCode - 22 Mar 2008 18:30 GMT
> In my BusinessLogicLayer, there are many places where I call the
> DataAccessLayer.
[quoted text clipped - 5 lines]
>
> adv-thanks-ance...

if you static methods use different connection is no problem.
Peter Bromberg [C# MVP] - 22 Mar 2008 20:40 GMT
The SqlHelper v2.0 class from Microsoft, which is considered "best practices"
code,  has all static methods. In fact, even though it first came out in
2001, I still use it extensively.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net

> In my BusinessLogicLayer, there are many places where I call the
> DataAccessLayer.
[quoted text clipped - 5 lines]
>
> adv-thanks-ance...
sloan - 22 Mar 2008 22:04 GMT
To provide another view...I write my DAL's as non static methods.

The one reason is that I have overloaded constructors....which are
() //empty
(string dbInstanceName)

I use the Enterprise.Data library....and it allows the use of a default
"instanceName"....or you can specify a specific named instance.
"SourceDatabase"
"DesinationDatabase"

or

"VirginiaDatabase"
"TennesseeDatabase"

whatever your multiple db needs might be.

I could have done this just as easily with overloaded static methods.  But I
chose overloaded constructors instead.

..

If you are using SqlServer only...then the DAAB 2.0 is a great helper
library.

If you're using something besides Sql Server....or using SqlServer ~and~
another one...then I'd go EnterpriseLibrary.Data.

You can use the EnterpriseLibrary.Data with SqlServer only as well.  But it
has has overhead code you might not need.

If you write a really good DAL layer..you should be able to swap out DAAB
2.0 for EnterpriseLibrary.Data with little effort.

..

Check here for a sample.
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry
I have a 1.1 example as well, and it uses the DAAB 2.0.  Just look for it at
the blog.
(Custom Objects, ... .1.1)

> In my BusinessLogicLayer, there are many places where I call the
> DataAccessLayer.
[quoted text clipped - 5 lines]
>
> adv-thanks-ance...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.