public static void ConnectionAuth(string strServer) { XDocument xDoc = XDocument.Load(System.Web.HttpContext.Current.Server.MapPath(strFilePath)); var xElements = xDoc.Element("Servers").Elements("item").Where(x => x.Attribute("Name").Value.Equals(strServer)); XElement xElement = xElements.FirstOrDefault(); if (xElement == null) { return; } string strSrv = xElement.Attribute("Server").Value; string strDBName = xElement.Attribute("Database").Value; SetSession("CurrentServer", strSrv); SetSession("CurrentDatabase", strDBName); SqlDatabaseHelper.SwitchConnection(string.Format(System.Configuration.ConfigurationManager.ConnectionStrings["MyDbConn"].ToString(), strSrv, strDBName)); }