Sreedhar Danturthi
Sreedhar Danturthi

Reputation: 7601

Question regarding SQL connection in a web application

I have a doubt regarding the sql database connection that we open for performing CRUD statements on the database in the context of web application (a web store) in asp.net

What is advisable

or

I have read some where that a lot of resources are consumed to open and close the database connection every time.

I need your advice

Upvotes: 1

Views: 272

Answers (3)

Ron Harlev
Ron Harlev

Reputation: 16723

By default, MS SQL server uses connection pooling, so connections (using the exact same connection string) get assigned to a live connection kept in the pool by the server. You should open and close your connections to keep things tidy on your side.

Upvotes: 2

abatishchev
abatishchev

Reputation: 100368

Open only when you need it, and close immediately after.

In case of often usage, connection will be pooled, and in fact stay be opened, but up to SQL Server decision. That will gain you performance being transparent for the code.

Upvotes: 1

James Allen
James Allen

Reputation: 819

I would always recommend closing a connection after use. Your site can handle more traffic this way, since connections are not sitting idle. The overhead in opening a connection is minuscule.

Upvotes: 2

Related Questions