I'm new to WebAPI but have done MVC in the past. I created 2 projects WebServiceAlpha that houses the "backend" and EF etc, and WebServiceBeta that "uses" the Alpha.
In WebServiceBeta, I'm trying to create a data access layer so I created a class called DAL and it's very simple. I have the SqlConnection, but any attempt to code anything else results in "The name j does not exist in the current context".
All I'm trying to do is to connect to the database.
What I have tried:
namespace WebServiceBeta
{
public class DAL
{
SqlConnection j = new SqlConnection(@"data source=***;initial catalog=CRUDDB;User id=***;password=***;MultipleActiveResultSets=True");
j.
}
}
On the controller; however, the connection works fine:
public ActionResult Index( FormCollection frm )
{
SqlConnection j = new SqlConnection(@"data source=**;initial catalog=CRUDDB;User id=**;password=**;MultipleActiveResultSets=True")
j.Open();
if ( j.State==ConnectionState.Open)
{
ViewBag.CnState = "Yea - I'm open!";
}
Is there something else I'm missing? I can't imagine it being a "using" issue, I've added System.Data.SqlClient and System.Data.