Mazen313
Mazen313

Reputation: 528

unclosed sql connection

Suppose that i have an application that connects to a sql server, and this application connects to this server on the start of the application and close this connection on the exit of the application,i would like to know if any one can use this connection to connect to sql server

Upvotes: 1

Views: 423

Answers (2)

Ron Sijm
Ron Sijm

Reputation: 8758

I don't completely understand your question, however, connecting to a sql server on start and closing it on exit is a bad practice:

Assuming you just use a regular SqlConnection .net will create its own internal connection pool. Keeping it open the entire time could cause unwanted problems, for example by locking

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1063338

A single database connection will be restricted to the process that owns it. External applications will only have access to this connection via whatever API your application exposes.

However, inside that application, "connection pooling" means that different SqlConnection instances may all resolve to the same underlying unmanaged connection, as long as they don't overlap. More likely, repeated SqlConnection usage (different SqlConnection instances) will result in a low number of underlying connections.

Upvotes: 3

Related Questions