I've added a connection string in web.config. I made a class where a string calls it -
namespace WebApplication1.Classes
{
public class Connections
{
public string DBConn =
ConfigurationManager.ConnectionStrings["HomeDB"].ConnectionString;
}
}
Now from my default.aspx.cs page I want to call this DBConn so I can use it in that page.
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Console.WriteLine(Classes.Connections.DBConn);
}
}
}
The Classes.Connections.DBConn is not working. This is the error I get.
An object reference is required for the non-static field, method, or property 'WebApplication1.Classes.Connections.DBConn'
What am I doing wrong?