how do i access a Connection String in the app.config file  
Author Message
Eileen Ewen





PostPosted: Visual C# General, how do i access a Connection String in the app.config file Top

I've a Data Access Layer that needs to get the Connection String from the app.config file.

Tried using :

this.connectionString = ConfigurationManager.AppSettings["connectionString"];

but when I run the app the connectionString is null

the setting in the app.config file is

name="HDRDB.Properties.Settings.HDRDBConnectionString" connectionString="Data Source=NTS14;Initial Catalog=HDRDB;Persist Security Info=True;User ID=hdrd_dba;Password=password"

providerName="System.Data.SqlClient"

sorry if this is simple but its my first C# app

ee




Visual C#13  
 
 
Sagitt





PostPosted: Visual C# General, how do i access a Connection String in the app.config file Top

Try using:

this.connectionString = ConfigurationManager.ConnectionStrings["HDRDB.Properties.Settings.HDRDBConnectionString"].ConnectionString;

Also, make sure your project has a reference to System.Configuration.

HTH,

Rob


 
 
Eileen Ewen





PostPosted: Visual C# General, how do i access a Connection String in the app.config file Top

Thank you that worked fine.

Cheers.

ee