Good practice for opening / closing connections in an asp.net application?

I am working on a web application in ASP.net. My application has several pages, and all of them should display tables that are populated with a database. Right now, what I'm doing is, on every page, I open a database connection by executing a request specific to that page and close the db connection. Thus, this happens every time a user clicks a link to go to a new page or clicks a form control, for example, on a grid page.

I was wondering if this was a disaster in terms of performance. Is there a better way to do this?

+5
source share
4 answers

, : . /... , , - . .

/ , / . ... .

, ( ), "" , . , .

+9

. .

, , . , . , , , , ..

+3

MSDN - ADO.Net

, .

, , , . , , , , , .

+3

Linking database connections to internal code is bad practice. When you study, I suggest you use web services to interact with the user interface, and not to associate your data interactions with the user interface.

Like UI (Aspx page) → BLL (business logic level) → DAL (data access level)

Also try using the 'using' keyword in the DAL and remove the connections and everything after interacting with the DB

+2
source

All Articles