0

I'm having difficulty with getting WCF project working with my web application. I've got 3 projects under the solution including asp.net project, DAL, WCF, and WCF tries to use function from DAL, DAL looks up the database connection string from web.config file under asp.net project. However, every time I call database function it returns connection string of null. it seems like I can't access web.config in asp.net project from WCF project. The ideal scenario is to use DAL from both asp.net and WCF without modifying any code.

this DAL library inherit CommonApplication

public abstract class BaseDatabaseApplication : BaseApplication
    {

        protected readonly string myConnection; // connection string to the publisher (master) database




        public BaseDatabaseApplication()
        {
            // all connection strings are configured here, in the base class
            myConnection = CommonApplication.Configuration.ConnectionStrings.ConnectionStrings["myConnection"].ConnectionString;               
            // some function here
        }
}

BaseApplication.cs

public abstract class BaseApplication
    {
        // since its static, there will only be one instance of it.
        private static CommonApplication applications;

        public static CommonApplication Applications
        {
            get { return applications; }
            set { applications = value; }
        }
    }

CommonApplication.cs

public class CommonApplication
    {
        // only want to process the config once.
        private static Configuration configuration;

        public static Configuration Configuration
        {
            get { return configuration; }
            set { configuration = value; }
        }
}
maxiSK
  • 13
  • 3
  • what is your question? what have you tried?? – Stack User Aug 16 '12 at 01:48
  • From WCF, I'm trying to call database function in DAL project and DAL project should get the database connection string from web.config in asp.net project but it returns null value. WCF -> DAL -> asp.net (web.config) – maxiSK Aug 16 '12 at 02:02
  • did you try to write connection string to DAL's web.config? – Stack User Aug 16 '12 at 02:12
  • I don't have web.config in DAL project as it's not a web project but contains set of libraries and I prefer to not to make any modification in existing projects and libraries. currently, DAL will get settings including database connection string from web.config in asp.net project. – maxiSK Aug 16 '12 at 02:21
  • have a look this link maybe it can be helpful for you http://stackoverflow.com/questions/2548476/accessing-another-projects-settings-file – Stack User Aug 16 '12 at 02:30
  • thanks for your help, I have no problem to access connection string in web.config(asp.net) when the call is originated from asp.net project but not from WCF projects. – maxiSK Aug 16 '12 at 03:43

1 Answers1

0

The System.Configuration.ConfigurationManager class should deals with this situation.

string connectionString = ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

Try to adapt your application to use it.

AndyG
  • 39,700
  • 8
  • 109
  • 143
outlookrperson
  • 2,761
  • 7
  • 32
  • 49