locked
The specified default EntityContainer name 'DataEntities' could not be found in the mapping and metadata information. RRS feed

  • Question

  • User1724124194 posted

    Hi friends,

    I am creating a web application with 2 different databases with different connectionstrings. My connectionstrings are

    <connectionStrings>
    <add name="DiGenSqlConnection" connectionString="Data Source=jj;Initial Catalog=MTRSData;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=jj123;MultipleActiveResultSets=True;Connect Timeout=120" />
    <add name="DiGenProfilesConnection" connectionString="Data Source=jj;Initial Catalog=MTRSProfilesData;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=jj123;MultipleActiveResultSets=True;Connect Timeout=120" />
    </connectionStrings>

    I am using two ObjectModels for the site. my app.config file for Object Models are

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <connectionStrings>
    <add name="DiGenProfileDataEntities" connectionString="metadata=res://*/Data.DiGenProfileModel.csdl|res://*/Data.DiGenProfileModel.ssdl|res://*/Data.DiGenProfileModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=JJ;initial catalog=MTRSProfilesData;persist security info=True;user id=sa;password=jj123;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="DiGenSiteDataEntities" connectionString="metadata=res://*/Data.DiGenSiteModel.csdl|res://*/Data.DiGenSiteModel.ssdl|res://*/Data.DiGenSiteModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=JJ;initial catalog=MTRSData;persist security info=True;user id=sa;password=jj123;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
    </configuration>

    I am using the following code to connect ObjactModel

    var ecsbuilder = new EntityConnectionStringBuilder();
    ecsbuilder.Provider = "System.Data.SqlClient";
    ecsbuilder.ProviderConnectionString = DiGenConfig.ConnectionString;
    ecsbuilder.Metadata = @"res://*/Data.DiGenSiteModel.csdl|res://*/Data.DiGenSiteModel.ssdl|res://*/Data.DiGenSiteModel.msl";
    string connectionString = ecsbuilder.ToString();
    InjectionConstructor connectionStringParam = new InjectionConstructor(connectionString);

    var ecsbuilderProfile = new EntityConnectionStringBuilder();
    ecsbuilderProfile.Provider = "System.Data.SqlClient";
    ecsbuilderProfile.ProviderConnectionString = DiGenConfig.ConnectionStringProfile;
    ecsbuilderProfile.Metadata = @"res://*/Data.DiGenProfileModel.csdl|res://*/Data.DiGenProfileModel.ssdl|res://*/Data.DiGenProfileModel.msl";
    string connectionStringProfile = ecsbuilder.ToString();
    InjectionConstructor connectionStringProfileParam = new InjectionConstructor(connectionStringProfile);

    //Registering object context
    container.RegisterType<DiGenObjectContext>(new UnityPerExecutionContextLifetimeManager(), connectionStringParam);
    container.RegisterType<DiGenProfileObjectContext>(new UnityPerExecutionContextLifetimeManager(), connectionStringProfileParam);

    After doing all these practices My first ObjectModel (DiGenSiteModel) is working fine but the other one is not working and I get the following error

    Server Error in '/' Application.

    The specified default EntityContainer name 'DiGenProfileDataEntities' could not be found in the mapping and metadata information.
    Parameter name: defaultContainerName

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: The specified default EntityContainer name 'DiGenProfileDataEntities' could not be found in the mapping and metadata information.
    Parameter name: defaultContainerName

    Source Error:


    Line 56: /// Initialize a new DiGenProfileDataEntities object.
    Line 57: /// </summary>
    Line 58: public DiGenProfileObjectContext(string connectionStringProfile)
    Line 59: : base(connectionStringProfile, "DiGenProfileDataEntities")
    Line 60: {

    Source File: H:\MyProject\DiGen.Libraries\Data\DiGenProfileModel.Designer.cs Line: 58

    Stack Trace:


    [ArgumentException: The specified default EntityContainer name 'DiGenProfileDataEntities' could not be found in the mapping and metadata information.
    Parameter name: defaultContainerName]
    System.Data.Metadata.Edm.ClrPerspective.SetDefaultContainer(String defaultContainerName) +8510251
    System.Data.Objects.ObjectContext.set_DefaultContainerName(String value) +69
    System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +40
    DiGen.Libraries.Data.DiGenProfileObjectContext..ctor(String connectionStringProfile) in H:\MyProject\DiGen.Libraries\Data\DiGenProfileModel.Designer.cs:58
    BuildUp_DiGen.Libraries.Data.DiGenProfileObjectContext(IBuilderContext ) +200
    Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
    Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +195
    Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
    Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +113
    Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +48
    BuildUp_DiGen.Libraries.Directory.CountryService(IBuilderContext ) +113
    Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
    Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +195
    Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
    Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +163

    [ResolutionFailedException: Resolution of the dependency failed, type = "DiGen.Libraries.Directory.ICountryService", name = "(none)".
    Exception occurred while: Calling constructor DiGen.Libraries.Data.DiGenProfileObjectContext(System.String connectionStringProfile).
    Exception is: ArgumentException - The specified default EntityContainer name 'DiGenProfileDataEntities' could not be found in the mapping and metadata information.
    Parameter name: defaultContainerName
    -----------------------------------------------
    At the time of the exception, the container was:

    Resolving DiGen.Libraries.Directory.CountryService,(none) (mapped from DiGen.Libraries.Directory.ICountryService, (none))
    Resolving parameter "context" of constructor DiGen.Libraries.Directory.CountryService(DiGen.Libraries.Data.DiGenProfileObjectContext context)
    Resolving DiGen.Libraries.Data.DiGenProfileObjectContext,(none)
    Calling constructor DiGen.Libraries.Data.DiGenProfileObjectContext(System.String connectionStringProfile)
    ]
    Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +327
    Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +15
    Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, ResolverOverride[] overrides) +81
    DiGen.Libraries.Infrastructure.UnityDependencyResolver.Resolve() in H:\MyProject\DiGen.Libraries\SiteFiles\Infrastructure\UnityDependencyResolver.cs:297
    DiGen.Libraries.Infrastructure.IoC.Resolve() in H:\MyProject\DiGen.Libraries\SiteFiles\Infrastructure\IoC.cs:63
    DiGen.Web.BaseUserControl.get_CountryService() in H:\MyProject\MySite.Web\Controls\BaseUserControl.cs:75
    DiGen.Web.Modules.Search.FillLocation() in H:\MyProject\MySite.Web\Modules\Search.ascx.cs:31
    DiGen.Web.Modules.Search.Page_Load(Object sender, EventArgs e) in H:\MyProject\MySite.Web\Modules\Search.ascx.cs:18
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
    System.Web.UI.Control.OnLoad(EventArgs e) +91
    System.Web.UI.Control.LoadRecursive() +74
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

    Please help me. 

    Monday, October 7, 2013 10:49 AM

Answers

  • User1143442848 posted

    var ecsbuilderProfile = new EntityConnectionStringBuilder();
    ecsbuilderProfile.Provider = "System.Data.SqlClient";
    ecsbuilderProfile.ProviderConnectionString = DiGenConfig.ConnectionStringProfile;
    ecsbuilderProfile.Metadata = @"res://*/Data.DiGenProfileModel.csdl|res://*/Data.DiGenProfileModel.ssdl|res://*/Data.DiGenProfileModel.msl";
    string connectionStringProfile = ecsbuilder.ToString();
    InjectionConstructor connectionStringProfileParam = new InjectionConstructor(connectionStringProfile);

    Hi,

    According to your code, I suggest you please try to replace

    string connectionStringProfile = ecsbuilder.ToString();

    with below:

    string connectionStringProfile = ecsbuilderProfile.ToString();

    Please have a try.

    Best Regards,

    Lisa Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 8, 2013 1:14 AM

All replies

  • User1724124194 posted

    Please help me to solve my issue

    Tuesday, October 8, 2013 12:39 AM
  • User1143442848 posted

    var ecsbuilderProfile = new EntityConnectionStringBuilder();
    ecsbuilderProfile.Provider = "System.Data.SqlClient";
    ecsbuilderProfile.ProviderConnectionString = DiGenConfig.ConnectionStringProfile;
    ecsbuilderProfile.Metadata = @"res://*/Data.DiGenProfileModel.csdl|res://*/Data.DiGenProfileModel.ssdl|res://*/Data.DiGenProfileModel.msl";
    string connectionStringProfile = ecsbuilder.ToString();
    InjectionConstructor connectionStringProfileParam = new InjectionConstructor(connectionStringProfile);

    Hi,

    According to your code, I suggest you please try to replace

    string connectionStringProfile = ecsbuilder.ToString();

    with below:

    string connectionStringProfile = ecsbuilderProfile.ToString();

    Please have a try.

    Best Regards,

    Lisa Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 8, 2013 1:14 AM
  • User1724124194 posted

    According to your code, I suggest you please try to replace
    string connectionStringProfile = ecsbuilder.ToString();

    with below:

    string connectionStringProfile = ecsbuilderProfile.ToString();

    Yes, that was my mistake because I copied the above code and forgot to change this line.

    Thank you very Much.....

    It solved my problem and I was worried about this issue since last three days.

    Thank you very Much.....

    Tuesday, October 8, 2013 2:11 AM