I am using wcf to develope a web service.
In this, I need to fetch few records from database using Ado.net.
I have used Wcf Service Library to create a web service.
The problem here I am getting is when I am trying to communicate with the Database it is giving me some weired errors.
For ex:-
When I am trying to use Connection String,
string ConString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(ConString); // it give me error here in ConString
Error:- A field initializer cannot refrence the non-static field, method or property "ProjectName.ClassName.ConString"
But this works fine in normal Asp.net Web Application.
or when I am using like this,
string ConString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con;
Sql ...
Go to the complete details ...