Set ConnectionString of Enterprise Library 4.1 at class library from web.config

Posted on 2009-02-09
Last Modified: 2013-11-25
Hi Experts,,

I have created a new project having 2 projects ( web and class library). However i need to have all data access classes embedded on the class library so i need to pass the connection string from the web.config to class library then assign to enterprise library database factory then execute.

What is the best way for doing this ??

Question by:Abu Hamdan
    1 Comment
    LVL 7

    Accepted Solution

    Problem solved by using this code:

       public static Database CreateDatabase()
                string connectionString = App_Settings.portalCnnStr;
                DbProviderFactory provider =
                return new GenericDatabase(connectionString, provider);   // dbProviderFactory = System.Data.SqlClient


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now