I am trying to connect to database using app.config instead of putting the connection settings in each form. Below are the coding that i used. It works in Microsoft Visual Studio 2003. However, it doesn't works in Microsoft Visual Studio 2005. It states that the System.Configuration is obsolete. Does anyone know why and how to solve the problem?

Thank you.

app.config
------------------------------------------------------------------------------------------------------
<?xml version="1.0" √úncoding="utf-8" ?>
<configuration>
<appSettings>
<add key = "constring" value="data source=Testing; initial catalog=Northwind; Integrated Security=SSPI" />
</appSettings>
</configuration>

Form
--------------------------------------------------------------------------
Using System.Configuration;

// Setup Connection
string constr = ConfigurationSettings.AppSettings["constring"].ToString();
SqlConnection conn = new SqlConnection(constr);

hi,
In VS 2005, the ConfigurationSettings is obsolete. try using the following.

Add a reference to System.Configuration,

then in the code,

using System.Configuration;

string connectionstring=ConfigurationManager.AppSettings["Connection"];
and then use the connectionstring variable.

hope this helps.

Regards

Exelio

This article has been dead for over six months. Start a new discussion instead.