Database Connection

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 84
Reputation: rinoa04 is on a distinguished road 
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Database Connection

 
0
  #1
Oct 3rd, 2007
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);

Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 57
Reputation: Exelio is an unknown quantity at this point 
Solved Threads: 0
Exelio Exelio is offline Offline
Junior Poster in Training

Re: Database Connection

 
0
  #2
Oct 3rd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 84
Reputation: rinoa04 is on a distinguished road 
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Re: Database Connection

 
0
  #3
Oct 3rd, 2007
Ok. I got it now. Thank you very much Exelio
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 57
Reputation: Exelio is an unknown quantity at this point 
Solved Threads: 0
Exelio Exelio is offline Offline
Junior Poster in Training

Re: Database Connection

 
0
  #4
Oct 3rd, 2007
hi

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

Regards

Exelio
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC