I am trying to connect to a SQL Server database from my ASP.Net MVC 4 application.
The connection string I have is:
<add name="EmployeeContext"
connectionString="server=DEVELOPER-PC; database=Sample; integrated security=SSPI"
providerName="System.Data.SqlClient"/>
The error message I get is this:
The underlying provider failed on Open.
To try and fix this issue added this piece of code into my connection string in VB user id=js;password=jess1;
but to no avail.
Another site said to add my main computer user to SQL and this didnt work either.
My model class:
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
My controller:
public ActionResult Details(int id)
{
EmployeeContext employeeContext = new EmployeeContext();
Employee employee = employeeContext.Employees.Single(x => x.EmployeeId == id);
return View(employee);
}
EDIT
I also have this model in my application
namespace Department_Employee.Models
{
[Table("tblEmployee")]
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
}
}
Can anybody see where I have gone wrong?