I have a SelfHosted WCF service and when I'm trying to read connection string from web.config file
string conn = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
Object reference not set to an instance of an object.
<add name="MyConnectionString" connectionString="server=192.168.1.2;database=TestDB;uid=sa;pwd=saas" providerName="System.Data.SqlClient"/>
I found the solution. It was my fault. In the VS solution I have 2 projects: First(WCF service) and Second(Console app that hosted my service).
The problem was that I added
connectionStrings to the First project in
After I added the
connectionStrings to the Second project in
app.config file, everything works fine