Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET WCF entity
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:
 
<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
 
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.

 
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'
 
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 9-Jul-13 22:51pm
Edited 10-Jul-13 0:12am
(no name)7.8K
v3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 504
1 Maciej Los 349
2 Kornfeld Eliyahu Peter 325
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 10 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100