Reputation: 520
I want to retrieve the ConnectionString
from the app.config
in the DataAccess class library for use in Entity Framework's .edmx
model of the application by using this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace BusinessLogicAndData
{
public class Connection
{
public static RevenueData GetContext()
{
//ConfigurationManager configManager = new ConfigurationManager();
string conString = ConfigurationManager.ConnectionStrings["RevenueData"].ConnectionString;
RevenueData RDC = new RevenueData(conString);
return RDC;
}
}
}
But each time the program runs, it throws a null reference exception complaining that
object reference is not set to an instance of an object
I have walked through the stack trace of the VS 2010 but I can't seem to pinpoint the problem. Please any suggestions about the origin of the exception.
Upvotes: 2
Views: 1209
Reputation: 236208
You should add connection string to App.Config
of your executable application (not to config in DataAccess library project).
Upvotes: 1