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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -