473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 26037
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GrantS | last post by:
I am unable to get the connection to work with using the app.config file. the connection works when I use 'in line' connection as below:...
4
by: Mark | last post by:
OK. Here we go. I have an ASP.NET application that does many hits to a SQL Server DB on a separate server. When I first created this application (2 years ago) and was very new to ASP/ASP.NET, to...
3
by: steve | last post by:
Hi, I heard you could put your db connection string into the web.config file to make it editable after you compile and/or deploy. I cant seem to find any info on this.. can any one help? Sample...
5
by: Fernando Lopes | last post by:
Hi there. In your opinion, where is the best place to put the connection string of a web application? Web.config, a constant into the code? I'm not using a component server, so it's not an...
4
by: Andrew | last post by:
Hello, friends, I have two questions: (1) In asp.net, where is the best place to store DB connection string? (We have .dll to handle all DB queries.) (2) Any sample source code for client...
19
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet...
7
by: John A Grandy | last post by:
If a SQLDataSource add the following to my web.config file, how to I programmatically extract the connection string: <configuration> <appSettings/> <connectionStrings> <add...
2
by: Jon Paal | last post by:
..net 2.0 can't retrieve connection string from web.config, always returns error message -- what's missing ?? ======web.config ========= <appSettings> <connectionStrings> <add...
3
by: dbuchanan | last post by:
Here is part of the web.config - it is given to me like this. ======================= <configuration> <appSettings/> <connectionStrings> <add name="MyConnectionName" connectionString="Data...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.