User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 456,524 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,809 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1458 | Replies: 3
Reply
Join Date: Sep 2006
Posts: 83
Reputation: rinoa04 is on a distinguished road 
Rep Power: 3
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Database Connection

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

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Posts: 57
Reputation: Exelio is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Exelio Exelio is offline Offline
Junior Poster in Training

Re: Database Connection

  #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  
Join Date: Sep 2006
Posts: 83
Reputation: rinoa04 is on a distinguished road 
Rep Power: 3
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Re: Database Connection

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

Re: Database Connection

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 4:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC