469,353 Members | 2,053 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

Accessing Connection String from appSettings

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.

Jan 23 '06 #1
3 25856
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.

Jan 23 '06 #2
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
Jan 23 '06 #3
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.

Jan 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Fernando Lopes | last post: by
4 posts views Thread by Andrew | last post: by
7 posts views Thread by John A Grandy | last post: by
2 posts views Thread by Jon Paal | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.