Accessing Connection String from appSettings

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.
 
?

=?iso-8859-1?Q?Patrik=20L=f6wendahl=20[C#=20MVP]?=

Hello Vijayata,

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

Horst Nabulke

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
 
?

=?iso-8859-1?Q?Patrik=20L=f6wendahl=20[C#=20MVP]?=

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top