public static bool SetConnection(ProviderName providerName,string connString) { bool rv=false; ConnectionStringSettings setting = new ConnectionStringSettings(); setting.Name = Guid.NewGuid().ToString() + "_Db"; setting.ProviderName = providerName.GetStringValue(); setting.ConnectionString = connString; ConfigurationManager.ConnectionStrings.Add(setting); connStringName = setting.Name; var cString = ConfigurationManager.ConnectionStrings[connStringName].ToString(); if (TestConnect(cString)) return true; return rv; }