Re: Best connection management

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

.



Relevant Pages

  • Re: Ada DB bindings and APQ
    ... >>I didn't like the use of handles for database objects. ... > will ensure that the connection will not go away until at least one query ... > things which can be made with a connection. ... That is different to ODBC. ...
    (comp.lang.ada)
  • RE: Posible to speed up query update with Apllication.screenupdati
    ... Don't change anything on the database side; the only question is the most ... You create a connection by sending the connect string to the ODBC driver. ... (multiple queries). ... You now execute the query (there are several ways in ADO but I usually ...
    (microsoft.public.excel.programming)
  • Re: MS Access looks for .mdb rather than Progress schema
    ... It got past looking for pub.mdb, and looks like it tried to run the query ... I also tried putting the whole thing in the connection string: ... The settings for the Merant ODBC driver for ... default connect string means a jet database. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Word 2003 Closes upon update of sort order of table using Acce
    ... data connection file created to the database folder and created a dummy user ... connection is much faster and seems far more stable. ... incorporate OLE DB, they probably found themselves with a lot more problems ... embed a table or query name. ...
    (microsoft.public.word.mailmerge.fields)
  • Sql Server SCOPE_IDENTITY()
    ... I'm currenly in the process of writing a Database abstraction class ... SCOPE_IDENTITY query it is on the same connection as the INSERT query (which ...
    (microsoft.public.dotnet.framework.adonet)