Windows Phone Developers

Friday, April 16, 2010

How to retrieve specific connection string from App.Config file using C# (.NET)

Get specific connection string from App.Config file using C# (.NET)

The connection string can be retrieved from the App.Config file using ConnectionStrings method of ConfigurationManager. You need to add the following directive in the code:


using System.Configuration;

The ConnectionStrings method without any arguments will return a collection of Connection strings in the App.Config file. If you want to retrieve specific ones you can either pass an index or string to it

private static string retsettings(String sConnName)
        {
            try
            {
                ConnectionStringSettings sConnection = ConfigurationManager.ConnectionStrings[sConnName];
                return sConnection.ConnectionString;
            }
            catch (Exception ex1)
            {
                return null;
            }
            finally
            { }

            
        }
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment