472,805 Members | 944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 1304
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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.