string connection = "Data Source= " + @serverName + ";Initial Catalog=master;User ID= " + @rootUser + ";Password= " + @decryptedPass;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[connection].ConnectionString))
Does your configuration file contain a
setting with a
attribute that precisely matches the string you've built?
My guess is it doesn't, since that looks more like an actual connection string than the name of a connection string stored in the config file.
As a result,
, and your attempt to retrieve its
property will throw a
If you're not storing the connection string in the config file, then don't try to read it from the config file:
using (SqlConnection conn = new SqlConnection(connection))