c# - Dynamically set SQL connection string based on session -


session variable becomes null when called public partial class outside methods. if called inside methods value available. code initialize sql connection string not work intended.

public partial class doctor_default : system.web.ui.page {     sqlconnection con = new sqlconnection(session["connectionstring"].tostring());     protected void page_load(object sender, eventargs e)     {      } } 

maybe work you:

string constring; sqlconnection con;  protected void page_load(object sender, eventargs e) {     constring = session["connectionstring"].tostring();     // check here constring == null, if necessary.     con = new sqlconnection(constring); } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -