| | |
Database Connection
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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);
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);
•
•
Join Date: Aug 2006
Posts: 57
Reputation:
Solved Threads: 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
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
![]() |
Similar Threads
- database connection(select ,insert query) within javascript function (JSP)
- Login Page Database connection to MSAccess (VB.NET)
- Problem with database connection (JSP)
- Database Connection in Visual Studio 2005 (ASP.NET)
- Visual C++, Database connection, please help (C++)
- ASP file with database connection problem (ASP)
- error due to accessing database connection using jsp (JSP)
Other Threads in the C# Forum
- Previous Thread: Regarding regular expressions
- Next Thread: Modify an Object from another variable
| Thread Tools | Search this Thread |
.net access ado.net algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation event excel file form format formatting forms function gdi+ httpwebrequest image index input install interface java label list listbox mandelbrot math mouse mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remote remoting resource restore richtextbox server sleep socket sql statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml





