471,337 Members | 835 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 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 1238
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Sergey Klementiev | last post: by
25 posts views Thread by Sahil Malik [MVP] | last post: by
4 posts views Thread by Mantorok | last post: by
8 posts views Thread by JackRazz | last post: by
2 posts views Thread by Mark P | last post: by

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.