473,406 Members | 2,369 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,406 software developers and data experts.

Static Method returns DataReader

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
4 2155
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steven D'Aprano | last post by:
I've been doing a lot of reading about static methods in Python, and I'm not exactly sure what they are useful for or why they were introduced. Here is a typical description of them, this one...
1
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
18
by: Daniel Gustafsson | last post by:
Hi there, hmm, I've just started with C# and I'm experimenting with method overloading. It seems like it's not possible to override method using return types, only parameters. Is that by design,...
0
by: Peter Lin | last post by:
Dear all, I am using Microsoft.ApplicationBlocks.Data, for one thing I am not quite sure. Is the following static SqlHelper ExecuteReader method from source codes not thread saft in multithread...
10
by: Paschalis Pagonidis | last post by:
Hi, I have a class which all its attributes, properties and methods are static. However, I want a method to return an object that should be non-static. Is that possible?
9
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database...
4
by: Lerp | last post by:
Hi all, With regards to calling data from a database and filling in an editing form based on some query, which is the best (least intensive on processor) method for assigning the returned...
6
by: Mirek Endys | last post by:
Hello all, another problem im solving right now. I badly need to get typeof object that called static method in base classe. I did it by parameter in method Load, but i thing there should be...
1
TRScheel
by: TRScheel | last post by:
Platform: Windows Vista Language: ASPX / C# I am trying to make a business library for where I work, and I have everything figured out and done except for the ObjectDataSource portion. If any...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

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.