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

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -