public void GetConnectionString() { try { if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0) { connString = rootWebConfig.ConnectionStrings.ConnectionStrings["Expenses"]; if (connection == null) { connection = new SqlConnection(connString.ToString()); Session["Connection"] = connection; //connection.Open(); } } } catch (Exception e) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox", "alert('" + e.Message + "');", true); } finally { if (connection != null && connection.State == ConnectionState.Open) { connection.Close(); } } }
public db() { _settings = System.Configuration.ConfigurationManager.ConnectionStrings["Database"]; try { _sqlConnection = new System.Data.SqlClient.SqlConnection(); _sqlConnection.ConnectionString = _settings.ToString(); _sqlConnection.Open(); } catch (Exception msg) { } }
public void ToStringTest () { ConnectionStringSettings s = new ConnectionStringSettings ( "name", "connectionString", "provider"); Assert.AreEqual ("connectionString", s.ToString(), "A1"); }