hi Every One
Session value Null when dynamically created connection string in asp .net using linq
SessionUtility sessionobj = new SessionUtility(); sessionobj.setLoginName(txtName.Text); sessionobj.setPassword(txtPassword.Text); try { //Constructing connection string from the inputs StringBuilder Con = new StringBuilder("Data Source="); Con.Append("SERVER-PC\\SQLEXPRESS"); Con.Append(";Initial Catalog="); Con.Append("APB_New"); Con.Append(";User ID=sa;Password=option@123;timeout=20"); string strCon = Con.ToString(); updateConfigFile(strCon); //Create new sql connection SqlConnection Db = new SqlConnection(); //to refresh connection string each time else it will use previous connection string ConfigurationManager.RefreshSection("connectionStrings"); Db.ConnectionString = ConfigurationManager.ConnectionStrings["APBConnection"].ToString(); } catch (Exception E) { }---------------------------------------------------------------
public void updateConfigFile(string con) { //updating config file try { XmlDocument XmlDoc = new XmlDocument(); //Loading the Config file XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); foreach (XmlElement xElement in XmlDoc.DocumentElement) { if (xElement.Name == "connectionStrings") { xElement.FirstChild.Attributes[2].Value = con; } } XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); } catch (Exception ex) { } }
please reply ASAP.