473,396 Members | 1,797 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,396 software developers and data experts.

static properties in classes question

I've been playing with using static properties using a simple example and i
see the potential for some site performance boosts. As i'm a little new to
the concepts i'd like to ask if what i'm about to propose is possible and if
so a good idea.

I have a few data readers for various reports that are sql intensive, but
small (about 20-30 rows).
can i create a static datareader or a static dataadapter as a property? so
that it can be run once and kept in memory as a read only item? The data
would need to be refreshed a few times during the day as information changes.
--
Share The Knowledge. I need all the help I can get and so do you!
Sep 14 '07 #1
5 1328
I wouldn't recommend it. If you hold a data reader and don't close it,
then the connection associated with it is held open. The thing with a data
reader as well is that it works in a forward-only, read-only manner.
Because of that, the connection staying open, and no way to reopen the data
reader after it is closed, you are better off creating a new data reader
(along with a new connection) to use every time you need it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:CF**********************************@microsof t.com...
I've been playing with using static properties using a simple example and
i
see the potential for some site performance boosts. As i'm a little new to
the concepts i'd like to ask if what i'm about to propose is possible and
if
so a good idea.

I have a few data readers for various reports that are sql intensive, but
small (about 20-30 rows).
can i create a static datareader or a static dataadapter as a property? so
that it can be run once and kept in memory as a read only item? The data
would need to be refreshed a few times during the day as information
changes.
--
Share The Knowledge. I need all the help I can get and so do you!

Sep 14 '07 #2
thanks for responding,
My mistake reader was the wrong item to suggest better would be an adaptor
or a data table that can be bound on demand to a gridview for readonly data.

Do you think this would work? I'd even go for creating an object datasource
out of it if i can make it static.

Thank you!
--
Share The Knowledge. I need all the help I can get and so do you!
"Nicholas Paldino [.NET/C# MVP]" wrote:
I wouldn't recommend it. If you hold a data reader and don't close it,
then the connection associated with it is held open. The thing with a data
reader as well is that it works in a forward-only, read-only manner.
Because of that, the connection staying open, and no way to reopen the data
reader after it is closed, you are better off creating a new data reader
(along with a new connection) to use every time you need it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:CF**********************************@microsof t.com...
I've been playing with using static properties using a simple example and
i
see the potential for some site performance boosts. As i'm a little new to
the concepts i'd like to ask if what i'm about to propose is possible and
if
so a good idea.

I have a few data readers for various reports that are sql intensive, but
small (about 20-30 rows).
can i create a static datareader or a static dataadapter as a property? so
that it can be run once and kept in memory as a read only item? The data
would need to be refreshed a few times during the day as information
changes.
--
Share The Knowledge. I need all the help I can get and so do you!


Sep 14 '07 #3
You could possibly store a SqlDataAdapter as a static instance, however,
if you are pounding on it from multiple threads, then you are going to have
to synchronize access, and you are probably going to lose any performance
benefit that you gain. Also, you would have to pass the connection to your
method which uses the data adapter, and set the connection on the commands
attached to it, as you can't leave those open and on the command.

All in all, you are better off creating the connection, creating your
adapters, using it, and then disposing of it properly.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:26**********************************@microsof t.com...
thanks for responding,
My mistake reader was the wrong item to suggest better would be an adaptor
or a data table that can be bound on demand to a gridview for readonly
data.

Do you think this would work? I'd even go for creating an object
datasource
out of it if i can make it static.

Thank you!
--
Share The Knowledge. I need all the help I can get and so do you!
"Nicholas Paldino [.NET/C# MVP]" wrote:
> I wouldn't recommend it. If you hold a data reader and don't close
it,
then the connection associated with it is held open. The thing with a
data
reader as well is that it works in a forward-only, read-only manner.
Because of that, the connection staying open, and no way to reopen the
data
reader after it is closed, you are better off creating a new data reader
(along with a new connection) to use every time you need it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message
news:CF**********************************@microso ft.com...
I've been playing with using static properties using a simple example
and
i
see the potential for some site performance boosts. As i'm a little new
to
the concepts i'd like to ask if what i'm about to propose is possible
and
if
so a good idea.

I have a few data readers for various reports that are sql intensive,
but
small (about 20-30 rows).
can i create a static datareader or a static dataadapter as a property?
so
that it can be run once and kept in memory as a read only item? The
data
would need to be refreshed a few times during the day as information
changes.
--
Share The Knowledge. I need all the help I can get and so do you!



Sep 14 '07 #4
thank you,
Well, i had an idea, a good one but there are better ways to do this. I
really appreciate your advise and I'll follow it.

I do what i'm suggesting all the time in ColdFusion, only problem is it can
NOT be done with sp's must use ad hoc queries. Can you or anyone else
recomend a good way to cache a result set for the use i'm suggesting?
--
Share The Knowledge. I need all the help I can get and so do you!
"Nicholas Paldino [.NET/C# MVP]" wrote:
You could possibly store a SqlDataAdapter as a static instance, however,
if you are pounding on it from multiple threads, then you are going to have
to synchronize access, and you are probably going to lose any performance
benefit that you gain. Also, you would have to pass the connection to your
method which uses the data adapter, and set the connection on the commands
attached to it, as you can't leave those open and on the command.

All in all, you are better off creating the connection, creating your
adapters, using it, and then disposing of it properly.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:26**********************************@microsof t.com...
thanks for responding,
My mistake reader was the wrong item to suggest better would be an adaptor
or a data table that can be bound on demand to a gridview for readonly
data.

Do you think this would work? I'd even go for creating an object
datasource
out of it if i can make it static.

Thank you!
--
Share The Knowledge. I need all the help I can get and so do you!
"Nicholas Paldino [.NET/C# MVP]" wrote:
I wouldn't recommend it. If you hold a data reader and don't close
it,
then the connection associated with it is held open. The thing with a
data
reader as well is that it works in a forward-only, read-only manner.
Because of that, the connection staying open, and no way to reopen the
data
reader after it is closed, you are better off creating a new data reader
(along with a new connection) to use every time you need it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message
news:CF**********************************@microsof t.com...
I've been playing with using static properties using a simple example
and
i
see the potential for some site performance boosts. As i'm a little new
to
the concepts i'd like to ask if what i'm about to propose is possible
and
if
so a good idea.

I have a few data readers for various reports that are sql intensive,
but
small (about 20-30 rows).
can i create a static datareader or a static dataadapter as a property?
so
that it can be run once and kept in memory as a read only item? The
data
would need to be refreshed a few times during the day as information
changes.
--
Share The Knowledge. I need all the help I can get and so do you!


Sep 14 '07 #5
Why not store the results in a DataSet/DataTable and then access that?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:B1**********************************@microsof t.com...
thank you,
Well, i had an idea, a good one but there are better ways to do this. I
really appreciate your advise and I'll follow it.

I do what i'm suggesting all the time in ColdFusion, only problem is it
can
NOT be done with sp's must use ad hoc queries. Can you or anyone else
recomend a good way to cache a result set for the use i'm suggesting?
--
Share The Knowledge. I need all the help I can get and so do you!
"Nicholas Paldino [.NET/C# MVP]" wrote:
> You could possibly store a SqlDataAdapter as a static instance,
however,
if you are pounding on it from multiple threads, then you are going to
have
to synchronize access, and you are probably going to lose any performance
benefit that you gain. Also, you would have to pass the connection to
your
method which uses the data adapter, and set the connection on the
commands
attached to it, as you can't leave those open and on the command.

All in all, you are better off creating the connection, creating your
adapters, using it, and then disposing of it properly.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message
news:26**********************************@microso ft.com...
thanks for responding,
My mistake reader was the wrong item to suggest better would be an
adaptor
or a data table that can be bound on demand to a gridview for readonly
data.

Do you think this would work? I'd even go for creating an object
datasource
out of it if i can make it static.

Thank you!
--
Share The Knowledge. I need all the help I can get and so do you!
"Nicholas Paldino [.NET/C# MVP]" wrote:

I wouldn't recommend it. If you hold a data reader and don't
close
it,
then the connection associated with it is held open. The thing with a
data
reader as well is that it works in a forward-only, read-only manner.
Because of that, the connection staying open, and no way to reopen the
data
reader after it is closed, you are better off creating a new data
reader
(along with a new connection) to use every time you need it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yankee Imperialist Dog"
<Ya******************@discussions.microsoft.com >
wrote in message
news:CF**********************************@microso ft.com...
I've been playing with using static properties using a simple
example
and
i
see the potential for some site performance boosts. As i'm a little
new
to
the concepts i'd like to ask if what i'm about to propose is
possible
and
if
so a good idea.

I have a few data readers for various reports that are sql
intensive,
but
small (about 20-30 rows).
can i create a static datareader or a static dataadapter as a
property?
so
that it can be run once and kept in memory as a read only item? The
data
would need to be refreshed a few times during the day as information
changes.
--
Share The Knowledge. I need all the help I can get and so do you!



Sep 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
6
by: ~~~ .NET Ed ~~~ | last post by:
Yes, I think so at least... In C# you *can* have static properties which are quite useful when used properly. Now imagine the scenario where you need the ability (sp?) to implement a variety of...
5
by: Wysiwyg | last post by:
I'm new to c# programming and can't figure out how to avoid duplicating common code in multiple classes when I'm restricted to using different system base classes.. I'm using c# in asp.net to write...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
4
by: Mantorok | last post by:
Hi I have an ASP app which references a few static properties in some of the classes. I understand that you should use Session variables, but is it "possible" to have each session "not"...
8
by: JackRazz | last post by:
Is it possible to create a static class in vb.net like c# does? I want the code to create a single global instance of a class that is inherited from another class. I could use a module, but I...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
2
by: Mark P | last post by:
Still being relatively new to C++ I like to go back to review and rethink old designs to see where I could do things better. The issue I'm currently pondering is static vs. dynamic polymorphism,...
2
by: Random | last post by:
Here's a design question I'm curious to know if anyone here has wrestled with before... I'm writing my data access methods in classes in the App_Code directory. I know that I can easily...
7
by: wagger | last post by:
Hi! I am creating a set of static classes, one class for each "case" I have. The class should do and perform certain things, and the different static classes are doing different things. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...

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.