471,330 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Reading connection string from my App.Config file

Hello

This is my first post to this group. I just want to ask that how will I read
my connection string from the app.config file in C# 2008 and .Net 3.5. I
tried to use System.Configuration namespace but I think missing something.

here is my app.config file

-----------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add
name="Containers.Properties.Settings.Custom_JobCon nectionString"
connectionString="Data Source=196.3.3.3;Initial
Catalog=Custom-Job;User ID=sa;Password=altsds"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
-------------------------------------------------------------------------------------------------------------------

Thanks in Advance
Abul Hasan Lakhani.
Jul 3 '08 #1
2 6351
On Wed, 02 Jul 2008 22:03:55 -0700, Abul Hasan Lakhani
<ab*********@ecsonline.com.pkwrote:
This is my first post to this group. I just want to ask that how will I
read
my connection string from the app.config file in C# 2008 and .Net 3.5. I
tried to use System.Configuration namespace but I think missing
something.
If you're just using the project's Properties to store the string, then
you can access the string via the Properties.Settings.Default property for
your project.

If you're not storing the connection string that way, then you should be.
Otherwise you have to use the ConfigurationManager directly, which is a
pain (well, at least compared to using the Designer-provided Settings
class :) ).

Pete
Jul 3 '08 #2
Hi Abul,

You need some sort of System.Configuration.ConfigurationManager.Connecti onStrings["Containers.Properties.Settings.Custom_JobConnecti onString"]
Regards, Alex Meleta
mailto:am*****@gmail.com; blog:devkids.blogspot.com
Jul 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jon Davis | last post: by
2 posts views Thread by news.microsoft.com | last post: by
9 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by

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.