Link to home
Create AccountLog in
Avatar of NickMalloy
NickMalloyFlag 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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer