Accessing Connection String from appSettings

  • Thread starter Thread starter Vijayata
  • Start date Start date
V

Vijayata

Hi,

Can anyone help me for how to access connection string defines in
App.config file in an Windows form application.
I`m doing project in C#.NET and SQL Server2000.
So you are also pleased to give me suggestions on the above mentioned
platforms.

Thanks.
 
Hello Vijayata,

Yo have to set a reference to System.Configuration and then use the ConfigurationManager
class.
 
Am 23 Jan 2006 02:09:35 -0800 schrieb Vijayata:
Hi,

Can anyone help me for how to access connection string defines in
App.config file in an Windows form application.
I`m doing project in C#.NET and SQL Server2000.
So you are also pleased to give me suggestions on the above mentioned
platforms.

Thanks.

Hi,

to read the connection string out of your app.config file in your
application try something like this (e.g. for Oracle):

String myConnection =
ConfigurationSettings.AppSettings["connectStringORA"];
myConn = new OracleConnection(myConnection);

Your app.config file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="connectStringORA" value="Data Source=xxx;" />
</appSettings>
</configuration>

To learn more about connection strings, this page is quite interesting:

http://www.connectionstrings.com/

Bye

Horst
 
Hello Patrik,

System.Configuration.dll that is .. The ConfigurationManager class is in
the System.Configuration namespace.

string connectionString = ConfigurationManager.ConnectionStrings["importDb"].ConnectionString;


--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net
http://www.cornerstone.se
Hello Vijayata,

Yo have to set a reference to System.Configuration and then use the
ConfigurationManager class.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net
http://www.cornerstone.se
Hi,

Can anyone help me for how to access connection string defines in
App.config file in an Windows form application.
I`m doing project in C#.NET and SQL Server2000.
So you are also pleased to give me suggestions on the above mentioned
platforms.
Thanks.
 
Back
Top