Using Entity framework with SQL Server 2012 (local *.mdf database) c# entity-framework sql-server


I am trying to create a database in an MVC project. Code-First approach. I wrote my models and a DbContext database. I am having trouble making the connection to the database. My suspect that the problem is in my connection string but I am not sure. the database I want will consist of two tables, which are defined as follows:

public class EmployeeRequest
    public int EmployeeRequestId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string UserName { get; set; }
    public int ExtNumber { get; set; }
    public bool isProcessed { get; set; }
    public virtual ICollection<ChangeOrder> ChangeOrders { get; set; }


public class ChangeOrder
    public int ChangeOrderId { get; set; }
    public short Operation { get; set; } //0 - Add, 1- delete
    public int TargetExt { get; set; }
    public short Status { get; set; } //0- Pending, 1- Approved, 2- Denied
    public DateTime DtRequested { get; set; }
    public DateTime DtProcessed { get; set; }
    public DateTime DtChangesApplied { get; set; }
    public int EmployeeRequestID { get; set; }
    public virtual EmployeeRequest Request { get; set; }

The DbContext class is:

public class RequestsContext : DbContext
    public DbSet<EmployeeRequest> EmployeeRequests { get; set; }
    public DbSet<ChangeOrder> ChangeOrders { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)

Connection string:

<add name="RequestsContext" 
     connectionString="Data Source=(LocalDb);Database=Requests.mdf;Trusted_Connection=True"/>

The error I get says that the connection could not be made to the host.

I am nor sure why this is happening. Any Ideas?

7/29/2013 9:22:21 PM

Popular Answer

Please check the application has access to .mdf file location. If your application resides in "myDocuments" etc type of folders, the application may not have access to it by default.

7/29/2013 8:55:05 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow