My solution has 2 projects: and winform app and a class library. In the class library project I have an app.config file with the following xml (VS2005): <?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="BKT_IMG_ConnectionString" connectionString="Data Source=VALMIRC1;Initial Catalog=BKT_IMG;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="DBConnStr" value="Integrated Security=SSPI;Persist Security Info=False;User ID=bktadmin;Password=Imagem;Initial Catalog=BKT_IMG;Data Source=10.50.7.62" /> </appSettings> </configuration> My class is tryiong to read the connectionStrings section with the following code: using System.Configuration; using gDB = GlobalDataBase.GlobalDB; namespace MDIRules { public class Checks { public Checks() { gDB.ConnectionString = ConfigurationManager.ConnectionStrings["BKT_IMG_ConnectionString"].ToString(); } } } and I'm facing a system.nullreferenceException : Object reference no set to an instance of an object. Why? Why? I've included System.Configuration reference to my project as I saw on other posts and still cannot read this section. Any help will be apreciated Thanks
Sorry. I got it. the section cant be in the app.config class project. It must be in the application app.config file. Sad but True... On 1 jul, 17:07, VC wrote: > My solution has 2 projects: and winform app and a class library. In > the class library project I have an app.config file with the following > xml (VS2005): > > <?xml version="1.0" encoding="utf-8" ?> > <configuration> > > <connectionStrings> > <add name="BKT_IMG_ConnectionString" > connectionString="Data Source=VALMIRC1;Initial > Catalog=BKT_IMG;Integrated Security=True" > providerName="System.Data.SqlClient" /> > </connectionStrings> > > <appSettings> > <add key="DBConnStr" value="Integrated Security=SSPI;Persist > Security Info=False;User ID=bktadmin;Password=Imagem;Initial > Catalog=BKT_IMG;Data Source=10.50.7.62" /> > </appSettings> > </configuration> > > My class is tryiong to read the connectionStrings section with the > following code: > > using System.Configuration; > using gDB = GlobalDataBase.GlobalDB; > > namespace MDIRules > { > public class Checks > { > public Checks() > { > gDB.ConnectionString = > ConfigurationManager.ConnectionStrings["BKT_IMG_ConnectionString"].ToString(); > } > } > > } > > and I'm facing a system.nullreferenceException : Object reference no > set to an instance of an object. Why? Why? I've included > System.Configuration reference to my project as I saw on other posts > and still cannot read this section. > > Any help will be apreciated > > Thanks