Not able to read the value of Connection String:  from Config file in with c#

Posted on 2008-10-07
Last Modified: 2012-05-05
Hi I am using  a class library for retuning the connection string in configfile.i have created a config class and configconstanr class.In configconstant class i have defined the connection string name.And in the config class i m returing the connection string.The beleow code i am using

namespace MyLifeSpaceCommonExt.Common
    public class Config
        public static string MyLifeSpaceConnectionStringFromDLLConfig
            get { return GetConnectionStringFromDLLConfig(Constants.ConfigConstants.MyLifespaceConnectionString); }
        public static string GetConnectionStringFromDLLConfig(string name)
            ConnectionStringSettings conn ;

            string value = null;
                conn = GetConfig().ConnectionStrings.ConnectionStrings[name];
                value = conn.ConnectionString;
            catch (Exception ex)
                throw new Exception(string.Format("Not able to read the value of Connection String: '{0}' from Config file", name), ex);
            return value;
        public static Configuration GetConfig()
            string dllName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".dll";
            string path = System.IO.Path.Combine(MyLifeSpaceCommonLibExtFromWebConfig, dllName);
            Configuration config = ConfigurationManager.OpenExeConfiguration(path);
            AssemblyInfo a = new AssemblyInfo(dllName);
            return config;
        public static string MyLifeSpaceCommonLibExtFromWebConfig
            get { return GetAppSettingsFromWebConfig(Constants.ConfigConstants.MyLifeSpaceCommonLibExtPath); }

        public static string GetAppSettingsFromWebConfig(string name)
            string value = "";
                value = WebConfigurationManager.AppSettings[name];
            catch (Exception ex)
                throw new Exception(string.Format("Not able to read the value of '{0}' from Config file", name), ex);
            return value;


in GetConnectionStringFromDLLConfig method i m getting connectionstring value as null.

So looking for help,

Question by:tanu80
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 96

Expert Comment

by:Bob Learned
ID: 22660089
LVL 25

Accepted Solution

apeter earned 250 total points
ID: 22660652
Is your Config file is like below ? and you are trying to fetch "ConnStr1' according to below example ?

    <add name="ConnStr1" connectionString="LocalSqlServer: data source=;Integrated Security=SSPI;Initial Catalog=aspnetdb"
      providerName="System.Data.SqlClient" />

Author Closing Comment

ID: 31503845
i fix the issues after getting help from u

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS question 16 63
Read top line from CSV file 14 60
Health check of winows and webservces 5 53
C# Web service insert into Oracle table 8 46
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question