Release data source
-
I'm new to ASP.NET. Can anyone provide answer for my question below? 1. I have a database connection in Page 1; then after some process, it redirect to Page 2. Now my question is, if we don't close the connection (eg: MyDBConn.Close), after redirect to Page 2, will the resourse still grab in Page 1?
-
I'm new to ASP.NET. Can anyone provide answer for my question below? 1. I have a database connection in Page 1; then after some process, it redirect to Page 2. Now my question is, if we don't close the connection (eg: MyDBConn.Close), after redirect to Page 2, will the resourse still grab in Page 1?
You should always close the connection after working with the database. The best practice model for ADO.NET is aquire-query-release. You should always close a connection to the database as soon as your query is complete. Also, in ASP.NET the application is stateless. That means that when you request a page it creates a page, populates the page, streams the page to the browser, then deletes all resources used by the page. NOTE: If a connection to a database is not closed and it goes out of scope so that the garbage collector has to deal with it you will find that the connection stays open until such time as the garbage collector cleans up your mess. That might never happen because your application may break due to lack of connections before the garbage collector gets to it.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos
-
You should always close the connection after working with the database. The best practice model for ADO.NET is aquire-query-release. You should always close a connection to the database as soon as your query is complete. Also, in ASP.NET the application is stateless. That means that when you request a page it creates a page, populates the page, streams the page to the browser, then deletes all resources used by the page. NOTE: If a connection to a database is not closed and it goes out of scope so that the garbage collector has to deal with it you will find that the connection stays open until such time as the garbage collector cleans up your mess. That might never happen because your application may break due to lack of connections before the garbage collector gets to it.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos
Thank you for the advice. I'm very much appreciated.