I am creating a WCF Service.
It receives data from a iPhone App.
When the user sends data from their iPhone I need to save the data
into our Database useing WCF Service.
In my WCF application I am creating a class and wrote the following code.
string connstr = ConfigurationManager.ConnectionStrings["myconn"].ToString();
string SQLstr = "myStoredProc1";
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand(SQLstr, conn);
Intellisense is giving error for (constr, SQLstr)
A field initializer cannot reference the non-static field, method or
property.
Why I am getting this error. I see a lot of examples online with the same code.
Then why its giving error for my application. Is it because this class is in a WCF application.
This is how it sould look like: