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

Static Method returns DataReader

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

Jan 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
--
http://www.openmymind.net/
http://www.codebetter.com/
"Varangian" <of****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
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!
Jan 8 '07 #2

P: n/a
"Varangian" <of****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
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...
Jan 8 '07 #3

P: n/a
Thank you for the reply.. I have a better understanding of static stuff
in ASP.NET

Mark Rae wrote:
"Varangian" <of****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
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...
Jan 8 '07 #4

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

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Varangian" <of****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
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!

Jan 8 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.