to my yesterday's posting. Thanks William for your reply.
I understand it is a good practice to open connections as
late as possible and close them as early as possible.
My requirement is as follows:
I'm developing a class library that will be instantiated
by a COM component. My class library contains functions
that perform lot of mathematical calculations and read a
lot of data (using SqlDataReader) from the SQL Server
database. Once loaded into the memory (just one instance
of my C# class), the functions are executed many times in
an hour. Also, the class instance will reside in memory
indefinitely unless some error condition occurs in one of
the other services in our applications world in which
case, this class instance will be unloaded from memory.
I'm required to open at least 3 connections (since I will
be using 3 simulataneous data readers)
My questions are:
1.Is it ok to open the connections on startup and leave
them open as long as the class instance is in memory?
2.Will it not be a performance hit to open and close
connections very often?
3.Which is the best place to close the connections and
how?
4. Can you give me a brief example for implementing
IDisposable interface?
I appreciate your reply.
Subject: Re: closing open connections and other resources
From: "William Ryan" <do********@comcast.nospam.net>
Sent: 1/5/2004 12:46:19 PM
There are a lot of good reasons not to do this. Leaving
connections open
indefinitely has many potential problems, connection
pooling being the most
noticeable.
However, you could implement IDisposable and take care of
it there.
"csharpbeginner" <an*******@discussions.microsoft.com>
wrote in message
news:07****************************@phx.gbl...
My requirement is a certain database connection should be
closed only when the object is unloaded from memory. Is
the class destructor a good place to close open database
connections? Thanks in advance for your reply.
..