473,545 Members | 937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static Method returns DataReader

Hello,

I know that the kind of question below has been asked several
times....howeve r 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 2163
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.c omwrote in message
news:11******** *************@4 2g2000cwt.googl egroups.com...
Hello,

I know that the kind of question below has been asked several
times....howeve r 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.c omwrote in message
news:11******** *************@4 2g2000cwt.googl egroups.com...
I know that the kind of question below has been asked several
times....howeve r 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.c omwrote in message
news:11******** *************@4 2g2000cwt.googl egroups.com...
I know that the kind of question below has been asked several
times....howeve r 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.c omwrote in message
news:11******** *************@4 2g2000cwt.googl egroups.com...
Hello,

I know that the kind of question below has been asked several
times....howeve r 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
1983
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 from Guido: "The new descriptor API makes it possible to add static methods and class methods. Static methods are easy to describe: they behave...
1
2190
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 allocated on the stack but that's not a real reason. Which is OK because this isn't a real question, it's just a complaint dressed up to look like a reason...
18
4084
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, anyway around that or something? I.e. I'd like to have the same method return either a DataReader or a DataAdapter depending on the lvalue when...
0
1617
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 environment? Do we need to use lock or monitor to protect our data in the static method in multithread environment? Do the following codes have the...
10
6341
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
2645
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 operations on purchase orders and inventory. I have created a PurchaseOrder class and Inventory class to encapsulate operations like creating POs,...
4
1785
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 results to a variable. I have been using a couple of ways so far in my project.: 1. strFirst=objDR("Fname") 2. strFirst=objDR.GetOrdinal("Fname")
6
7201
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 way, how to get this information in called method. Thanks. public abstract class BaseClass {
1
1255
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 of you have used the ObjectDataSource, it binds to a static (you could bind it to a class that isnt static, but then the values and items within that...
0
7467
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7756
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.