Everyone knows that you must close the connection immediately after using it.
Due to a lack of a domain object model in my model, I had to leave the connection open for the full page life cycle. Essentially, I have a Just In Time property that opens a connection on the first call, and then on the .Unload (..) page, it will check if the db connection was ever open, and then close it if it was. Since it only takes a second, I was of the opinion that it is not too much different from closing immediately.
This is normal? Or should it be closed immediately after each use?
Thanks in advance.
This is not ideal, but I will not rewrite my application on top of it. If your page does not perform significant time-consuming work in different methods, the whole page life cycle should be fast. In practice, this may mean that your connection object is open a few milliseconds longer than it would otherwise. This may be significant in some scenarios, but it does not sound like it is in your case.
No, this is not normal.
- , . , . , , , ..
, , Page.Unload? . .
, .
, , , , , .
ASP.NET , . , , , "" .
, , /. 100 , , , , - 100 req/sec, .
. - (- --), ASP-, , , .
? , , ,
, (.. ) * , ,
* , , ,
, , . finally. " " , , , , / , , try/catch/finally.
, . , .
, , , , (), , . , , , , , , .
.
Itβs convenient for me to keep the connection open when using ORM ( Open Session in View ), so that after the initial desired selection, other data can be lazily loaded as needed. This works well when the page response time is reasonable so as not to bind connections.