943,708 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3207
  • C# RSS
Oct 3rd, 2007
0

Database Connection

Expand Post »
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
------------------------------------------------------------------------------------------------------
<?xmlversion="1.0"Üncoding="utf-8"?>
<
configuration>
<
appSettings>
<
addkey="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);

Reputation Points: 52
Solved Threads: 4
Junior Poster in Training
rinoa04 is offline Offline
84 posts
since Sep 2006
Oct 3rd, 2007
0

Re: Database Connection

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Exelio is offline Offline
57 posts
since Aug 2006
Oct 3rd, 2007
0

Re: Database Connection

Ok. I got it now. Thank you very much Exelio
Reputation Points: 52
Solved Threads: 4
Junior Poster in Training
rinoa04 is offline Offline
84 posts
since Sep 2006
Oct 3rd, 2007
0

Re: Database Connection

hi

You are welcome, please post the thread as solved.so that it can help someone.

Regards

Exelio
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Exelio is offline Offline
57 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Regarding regular expressions
Next Thread in C# Forum Timeline: Modify an Object from another variable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC