Static Method returns DataReader

V

Varangian

Hello,

I know that the kind of question below has been asked several
times....however I need a clear answer in my specific situation.

I have 2 methods. One returns an SqlDataReader and the other returns a
DataView. I was considering making them Static methods, so as to avoid
creating instance of the class which takes care of these methods, kind
of a helper class. Since its a web site the method may be accessed by
more than one user at one time....

the question is would it improve the performance if using Static method
in this case? Would it be a problem if using Static methods at all?

Thanks!
 
K

Karl Seguin

As long as your methods don't rely on any static fields global to the class
you'll be ok.

Yes it'll probably improve performance, but there are probably 100 things
you could do that'll improve it more. Seems like a pretty minor performance
improvement.

Karl
 
M

Mark Rae

I know that the kind of question below has been asked several
times....however I need a clear answer in my specific situation.

I have 2 methods. One returns an SqlDataReader and the other returns a
DataView. I was considering making them Static methods, so as to avoid
creating instance of the class which takes care of these methods, kind
of a helper class. Since its a web site the method may be accessed by
more than one user at one time....

Static methods which return ADO.NET objects are quite common in DALs
(database abstraction layers) - see the Microsoft DAAB for examples of
this...
the question is would it improve the performance if using Static method
in this case?

Not really - in fact, probably not at all...
Would it be a problem if using Static methods at all?

No, so long as you realise that any static variables will be shared across
multiple instances. This may or may not matter... E.g. if your site uses
only one SQL connection string, then it won't matter if it's shared across
multiple instances, as it will always be the same... However, if you have
other static variables which differ per session, then you will have serious
problems... :)

All my DAL methods are static because it's a bit less coding not to have to
do class instantiation every time...
 
V

Varangian

Thank you for the reply.. I have a better understanding of static stuff
in ASP.NET
 
M

Mark Fitzpatrick

You may see some performance increase due to not having to instantiate
objects. I ran a comparison test onetime of a very simple db object. All
this class did was create a user in a custom membership system. I ran
through a loop and found that the loop crashed due to the GC not being fast
enough to clean up the destroyed objects. When I tested the same using a
static method to do the database activity I was able to run over 15 times as
many loops (finally stopped simply because I didn't need any more bogus
users) and this was just with a simple insert.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top