| | |
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 activedirectory ado.net algorithm array barchart basic bitmap box broadcast buttons c# check checkbox client combobox contorl control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment development disabled displayingopenforms draganddrop drawing editing editor encryption enum event excel file form format forms function gdi+ httpwebrequest i18n image imageprocessing index input install java label list listbox mandelbrot math mathematics mouseclick mysql operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox rows server sleep socket sql statistics stream string table text textbox thread time timer update user usercontrol validation visualstudio webbrowser windows winforms wpf xml





