static properties in classes question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
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 said:
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]
- (e-mail address removed)

Yankee Imperialist Dog said:
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.
 
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]
- (e-mail address removed)
Yankee Imperialist Dog said:
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 said:
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]
- (e-mail address removed)

"Yankee Imperialist Dog" <[email protected]>
wrote in message
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.
 
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 said:
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]
- (e-mail address removed)
Yankee Imperialist Dog said:
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 said:
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]
- (e-mail address removed)

"Yankee Imperialist Dog" <[email protected]>
wrote in message
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.
 
Why not store the results in a DataSet/DataTable and then access that?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Yankee Imperialist Dog said:
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 said:
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]
- (e-mail address removed)
"Yankee Imperialist Dog" <[email protected]>
wrote in message
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!


:

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]
- (e-mail address removed)

"Yankee Imperialist Dog"
<[email protected]>
wrote in message
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top