0

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);

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Exelio
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.