I have an app.config file in my project as shown below.
I have following code to read the connection string:
string connectionstring = ConfigurationManager.ConnectionStrings["LibraryReservationSystemEntities"].ConnectionString;
It is showing exception as listed below.
Object reference not set to an instance of an object.
How can we correct it?
Note: This is a class library project. I copied this connection string from another project which is having EMDX file for EF. I have only one project in my current solution.
Note: I need to instantiate a ObjectContext (of EF) from a my project. The EMDX is available in a different project.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="LibraryReservationSystemEntities" connectionString="metadata=res://*/MyEDMtest.csdl|res://*/MyEDMtest.ssdl|res://*/MyEDMtest.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;AttachDbFilename=C:\DevTEST\Databases\LibraryReservationSystem.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
REFERENCE