I am using VisualStudio2012 for the development. I have created a class library EMPDAL
where I am using Employees table of NorthWnd
database to connect with Entity Framework and I tested the connection while configuring the database. I have written below code to get employees details.
public class EmplooyeeData
{
public static List<Employee> GetEmployees( int EmployeeId)
{
using (DbEntities dbContext = new DbEntities())
{
return dbContext.Employees.Where(x => x.EmployeeID == EmployeeId).ToList();
}
}
}
I created a console application to use this EMPDAL
so I had given the reference to my EMPDAL
and using below code to retrieve employee details
static void Main(string[] args)
{
List<EmpDAL.Employee> emp = new List<EmpDAL.Employee>();
emp = EmpDAL.EmplooyeeData.GetEmployees(1);
}
But when client code calls GetEmployees(1)
and debugger goes in to the EMPDAL.EmpDataGetEmployess
method then in return statement it throws the exception ![Exception is shown below]
The underlying provider failed on Open.
AppConfig I have used same in my class library and client application.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DbEntities" connectionString="metadata=res://*/EmployeeModel.csdl|res://*/EmployeeModel.ssdl|res://*/EmployeeModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=NorthWnd;user id=sa;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>