Click here to Skip to main content
15,887,952 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Experts

I have a rather research type of question for which I googled a lot but could not find any solution. May be anybody here can throw a some light on this.

In a website solution with app.config in a class library project and web.config in website project, is it possible that the class library project can directly use the connection string from web.config ? If yes, then what are the probable solutions ?
Posted

1 solution

there isn't any direct solution for this, but you can use a web service in your web application that get the web.config connection strings.
XML
namespace test
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public List<string> Conns()
        {
            var items = System.Configuration.ConfigurationManager.ConnectionStrings.Cast<string>().ToList();
            return items;
        }
    }
}

this web service return all connections in a list!
this is a base for you, go ahead and read online resources for help and if you have question about this ask again!
 
Share this answer
 
Comments
bbirajdar 5-Jun-12 5:05am    
Thank you Taha..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900