I have read several of the responses to this error and have tried all of them without success.
Here is what I have in the web.config file:
<connectionStrings>
<add name="SRM_MetricConnectionString" connectionString="Data Source=C3SRMSQL01T;Initial Catalog=SRM_Metric;Persist Security Info=True;User ID=**;Password=**"
providerName="System.Data.SqlClient" />
</connectionStrings>
Here is the call in the aspx.cs:
private void BindGridView()
{
// Get the connection string from Web.config.
// When we use Using statement,
// we don't need to explicitly dispose the object in the code,
// the using statement takes care of it.
using (SqlConnection conn = new SqlConnection("SRM_MetricConnectionString"))
{
// Create a DataSet object.
DataSet dsAnno = new DataSet();
In most of the responses SqlConnection(ConfigurationManager.ConnectionStrings["TestDataConnectionString"].ToString()); seems to be the format. When I do that the response is ConfigurationManager is not valid in this context.
Here are the using declarations I am using:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Data.Sql;
Any insight would be greatly appreciated. I am behind on getting this to work.
You must use same name in web.config and code behind to ConnectionStrings name.