Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have developed web application using VS 2010, WCF 4.0 and EF 4.1.1. My WCF Service developed with multiple EF Connection strings configured in web.config file those are taken from Entity Model app.config file. based on the parameters i am redirecting databases with EF Connection string at runtime.

My WCF4.0 web.config like:
HTML
<connectionstrings>
     <add name="WMSChennaiDEVEntities" connectionstring="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.0.89;Initial Catalog=WMSCMSWPROD;User ID=sa;Password=wms@123;MultipleActiveResultSets=True"" providername="System.Data.EntityClient" />
     <add name="WMSHyderabadDEVEntities" connectionstring="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.0.89;Initial Catalog=WMSHMSWPROD;User ID=sa;Password=wms@123;MultipleActiveResultSets=True"" providername="System.Data.EntityClient" />
    </connectionstrings>



And in my WCF Service.svc.cs file i have written function that has CenterId parameter and based on that ID i am changing my EF Connection strings like this

C#
WMSChennaiDEVEntities EcChennai;
    public void SetEntityModel(int CenterId)
    {
        if (CenterId == 4)
            EcChennai = new WMSChennaiDEVEntities(ConfigurationManager.ConnectionStrings["WMSChennaiDEVEntities"].ToString());
        else if (CenterId == 10)
            EcChennai = new WMSChennaiDEVEntities(ConfigurationManager.ConnectionStrings["WMSHyderabadDEVEntities"].ToString());

    }



Now I am going to convert this web application to VS 2012. I have created new EF Model with same entities and created new WCF Service. I have done some changes and everything is working fine when i am using only one EF Connection string.


C#
WMSMainEntities EntCenter = new WMSMainEntities();
    public List<wmscenter> GetCenters()
    {
        using (var tt = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted }))
        {
            EntCenter.Configuration.LazyLoadingEnabled = false;
            EntCenter.Configuration.ProxyCreationEnabled = false;
            var CenterColl = EntCenter.WMSCenters.ToList();
            tt.Complete();
            tt.Dispose();
            return CenterColl;
        }
    }


Now I am in big trouble when i am going to change EF Connecction Strings at runtime in the function. Entity is not taking up Connection String parameter as showing message 'does not contain a constructor that takes 1 arguments'

C#
WMSChennaiDEVEntities EcChennai;
public void SetEntityModel(int CenterId)
{
    if (CenterId == 4)
        EcChennai = new WMSChennaiDEVEntities(ConfigurationManager.ConnectionStrings["WMSChennaiDEVEntities"].ToString());
    else if (CenterId == 10)
        EcChennai = new WMSChennaiDEVEntities(ConfigurationManager.ConnectionStrings["WMSHyderabadDEVEntities"].ToString());
}

Error msg like:

Error 3 'CTScan.EntityLibrary.WMSChennaiDEVEntities' does not contain a constructor that takes 1 arguments D:\Code\CTScan\CTScan.WCFService\CTScanService.svc.cs 66 29 CTScan.WCFService


I have more than 300 methods already developed in the service. Every function is depend on the SetEntityModel(int CenterId) function.

So please help me to resolve how to call EF5 connection strings in runtime issue.

Thanks in advance.
Posted
Updated 9-Jul-13 23:12pm
v3

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