c# - EntityException was unhandled the underlying provider failed to open -
I am using VisualStudio2012 for development. I have created a class library EMPDAL , where I am using the employee table NorthWnd
to connect with the Entity Framework and when I configured the database I To get employee details I've written the code below.
Public class EmplooyeeData {public static list & lt; Employee & gt; GetEmployees (Int EmployeeId) {(DbEntities dbContext = new DbEntities ()) {return dbContext.Employees.Where (x = & gt; X. EmployeeID == EmployeeId) .toList (); }}
I created a console application to use this EMPDAL
, so I had given reference to my EMPDAL
and Below used code for getting employee details
Fixed zero main (string [] args {list & lt; EmpDAL.Employee & gt; Emp = new list & amp ;; EmpDAL.Employee & gt; (); Emp = EmpDAL.EmplooyeeData.GetEmployees (1); }
But when the client calls the code GetEmployees (1)
and goes into the debugger EMPDAL.EmpDataGetEmployess
method, then change In this statement throws an exception! [Exception is shown below]
The underlying provider failed on the open.
App Config I have used the same in my class library and client application.
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Configuration & gt; & Lt; ConfigSections & gt; & Lt ;! - For more information about entity framework configurations, go to http://go.microsoft.com/fwlink/?LinkID=237468 - & gt; Visit & Lt; Section Name = "Antenna Framework" type = "System.Data.nt.INNAL.configfile.EntitieFileWriter Description, Entity Framework, Version = 5.0.0.0, Culture = Neutral, Public Key Token = B77A5C 561934A90" Expected Promotion = "False "/> & Lt; / ConfigSections & gt; & Lt; ConnectionStrings & gt; & Lt; Add name = "DbEntities" connectionString = "metadata = res: //*/EmployeeModel.csdl | res: //*/EmployeeModel.ssdl | res: //*/EmployeeModel.msl; provider = System.Data.SqlClient; provider Connection string = & amp; quot; data source = localhost; initial list = northwand; user id = SA; multipleactive serialset = true; app = entity framework & amp; quot; "provider name =" System.Data.EntityClient "/ & Gt; & Lt; / ConnectionStrings & gt; & Lt; EntityFramework & gt; & Lt; DefaultConnectionFactory type = "System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> & Lt; / EntityFramework & gt; & Lt; / Configuration & gt;
You have mentioned at least two levels in your application (class library and A console application). For N-level applications, you need a connection string for your EF database, which is the web of all levels of your application. Config / App Required to be announced in the config, in which the ATI Framework is referenced.
Make sure that you have your console applications listed in the app.config in connection to your database connection string as well as app.config of the class library
@Yuliam As noted above, it is worth to ensure that you have the following connection string:
integrated security = true;
What does this when it is set to true, the net user tries to open the connection with user password. Set the integrated security to false if you want to open the connection string as a specific user.
Comments
Post a Comment