Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

static properties in classes question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yankee Imperialist Dog - 14 Sep 2007 14:56 GMT
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.
Signature

Share The Knowledge. I need all the help I can get and so do you!

Nicholas Paldino [.NET/C# MVP] - 14 Sep 2007 15:36 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> I've been playing with using static properties using a simple example and
> i
[quoted text clipped - 9 lines]
> would need to be refreshed a few times during the day as information
> changes.
Yankee Imperialist Dog - 14 Sep 2007 15:52 GMT
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!
Signature

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
[quoted text clipped - 16 lines]
> > would need to be refreshed a few times during the day as information
> > changes.
Nicholas Paldino [.NET/C# MVP] - 14 Sep 2007 16:09 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> thanks for responding,
> My mistake reader was the wrong item to suggest better would be an adaptor
[quoted text clipped - 36 lines]
>> > would need to be refreshed a few times during the day as information
>> > changes.
Yankee Imperialist Dog - 14 Sep 2007 16:54 GMT
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?
Signature

Share The Knowledge. I need all the help I can get and so do you!

>     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
[quoted text clipped - 46 lines]
> >> > would need to be refreshed a few times during the day as information
> >> > changes.
Nicholas Paldino [.NET/C# MVP] - 14 Sep 2007 17:32 GMT
Why not store the results in a DataSet/DataTable and then access that?

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> thank you,
> Well, i had an idea, a good one but there are better ways to do this. I
[quoted text clipped - 67 lines]
>> >> > would need to be refreshed a few times during the day as information
>> >> > changes.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.