For the most part opening and closing the connection to a database is
preferable to leaving it open for extended periods of time. Basically
it comes down to how frequently you will need to use the connection vs
many connections to your database you want to take up. What you have to
keep in mind is that most databases have some form of maximum user
connections (whether it is due to licensing or locking) and when your
application opens one up when it starts and doesn't close it until the
application is closed then that is one less connection that is available
for others to use.
Imagine that you have five connections available to your database and
ten database users... if you leave the connection open for your
application you can only get half the users into the system before it
locks the others out. At that point you either have to redesign or you
have to buy more licenses. However if you open and close connections
only as needed you'll find that five licenses is more than enough to
handle your users (unless the application constantly hammers the
database) and will actually handle a lot more users as well.
This is my 2 cents.
Have A Better One!
John M Deal, MCP
Necessity Software
Doug Durrett wrote:
I'm an old VB6 guy and in VB6 I could Open up a DataConnection object as
PUBLIC and use it anywhere in the application.
What do I do in C# or what is the "right" way. should I be creating a new
connection EVERY time I need something from the Database?
Just basics.... Thanks In Advance.
Doug