This is probably a silly question. Let’s say I have 20 event handlers that will go off after the postback. I want to open a connection to the database right before the events start, and then close it right after they end. Where would I put my open and close statements in my webform?
Share
Events are raised after
Page_Loadevent in the page’s life cycle. So you could open it there and close it inPage_PreRender.But actually i would suggest to avoid open connections at all. An open connection can not be reused. So you should always close connections as soon as possible where you’ve used it, best by using
using-statement.