Avatar of NickMalloy
NickMalloy
Flag for United States of America asked on

connection string code help

I can't figure out what is wrong with this code. The error is
A field initializer cannot reference the non-static field, method, or property 'clsKitInfo.connectionstring'      
this code sits in a class file named clsKitInfo. The problem is this line
protected SqlConnection cn = new SqlConnection(connectionstring);
protected string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["SQLConnect"].ConnectionString;
protected clsconnect cnstr = new clsconnect();
protected SqlConnection cn = new SqlConnection(connectionstring);

Open in new window

C#

Avatar of undefined
Last Comment
Guy Hengel [angelIII / a3]

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy