c# - ASP.net best practise - where do I connect to database from? -
cn = new sqlconnection( configurationmanager.connectionstrings["localsqlserver"].tostring()); cn.open();
where should code go assuming have content pages , master pages?
should put in master pages page_init
? accessible every stage of execution on content pages?
i'm used classic asp, it:
declare variables open connection process code close connection render html
but there lots of stages of page lifecycle in .net wondering best place code?
and connection need closing, or garbage handling take care of me?
for me id create dataaccess layer can remove database connectivity in codebehind files. webapp reference dal , expose public method allow dal interaction front end
in terms of opening , closing dal connections - wrap in using statement - takes care of opening , closing connection when required.
more information on can found here - http://davidhayden.com/blog/dave/archive/2005/01/13/773.aspx
Comments
Post a Comment