| | |
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
Views: 2472 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





