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
Post a Comment