Re: Best connection management
- From: "Miha Markic" <miha at rthand com>
- Date: Fri, 7 Sep 2007 10:46:47 +0200
No, this is not a good practice.
Instead, create a new connection instance and open it right before you need it. After the operation dispose it. Connection pooling will cache physicall connections for you (given the connecting string is the same).
This is the optimal usage.
In your case, you have a serious problem - you use a single connection instance (not thread safe) in a multithreaded app (which asp.net is).
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Hornet77" <neuro@xxxxxxxxxx> wrote in message news:uMt7IMS8HHA.3624@xxxxxxxxxxxxxxxxxxxxxxx
Hi all
I'm developing a software written in c# (.NET 2.0) with a SQL server 2005 database. I have 3 modules that need to access database:
- a simple ASP.NET website receiving event from remote devices via https calls
- a windows service running 24/7 that act as a server
- a winform application running as a client with user interface, launched by the user
3 modules use .NET remoting to communicate.
In order to query DB actually I'm using a single connection for each module, always opened (for the ASP.NET site I use a static instance of my "dbManager" class)... when I neeed to query the database I use the already opened connection and leave it opened for further operation.
Is this acceptable? what kind of problems can cause? Should I use another approach (open and close connection for every operation)?
Thanks in advance
.
- Follow-Ups:
- Re: Best connection management
- From: Hornet77
- Re: Best connection management
- References:
- Best connection management
- From: Hornet77
- Best connection management
- Prev by Date: Best connection management
- Next by Date: Re: Best connection management
- Previous by thread: Best connection management
- Next by thread: Re: Best connection management
- Index(es):
Relevant Pages
|