none
Entity Framework data access problem RRS feed

  • Question

  • My application is developed on Entity Framework 4.4, 

    Here is my code:

      Console.WriteLine("beging connection");
                string sql = IPDASEntities.SqlConnectString ;
                Console.WriteLine("the sql connection string "+sql);
                try{
                SqlConnection conn = new SqlConnection(sql);
     
                 conn.Open();
                if(  conn.State == ConnectionState.Open)
                {
                    Console.WriteLine("Connection is opened");
                }else{
     
                     Console.WriteLine("Connection is not open");
                }
                conn.Close();
                }catch(Exception ex){
     
                    throw ex;
                }
     
                try{
                    using (IPDASEntities ctx = newIPDASEntities(IPDASEntities.ConnectionString))
                    {
                        int cont = ctx.Database.SqlQuery<int>("select len('hello') ").SingleOrDefault();
                        Console.WriteLine("Entity framework works too");
                        List<ConfigDataList> conDataListList = ctx.ConfigDataLists.Where(t => t.ListName == "PartialImportDupCheckRules").ToList();
                        Console.WriteLine("The Configdatalist for PartialImportDupCheckRules   " + conDataListList.Count.ToString());
                    }
                }catch(Exception ex){
     
                    throw ex;
                }
                Console.ReadLine();

    The connection is fine, however, when program goes to 

                        

    List<ConfigDataList> conDataListList = ctx.ConfigDataLists.Where(t => t.ListName == "PartialImportDupCheckRules").ToList();

    I got the following error

    Error in getting configdatalist for ListName=PartialImportDupCheckRules
    System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for system.data: Method not found: 'Int32 System.Globalization.CultureInfo.()'. (C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config line 157) ---> System.MissingMethodException: Method not found: 'Int32 System.Globalization.CultureInfo.()'.
       at System.Data.DataSet.ValidateLocaleConstraint()
       at System.Data.DataSet.SetLocaleValue(CultureInfo value, Boolean userSet)
       at System.Data.DataSet.set_Locale(CultureInfo value)
       at System.Data.Common.HandlerBase.CloneParent(DataSet parentConfig, Boolean insenstive)
       at System.Data.Common.DbProviderFactoriesConfigurationHandler.CreateStatic(Object parent, Object configContext, XmlNode section)
       at System.Data.Common.DbProviderFactoriesConfigurationHandler.Create(Object parent, Object configContext, XmlNode section)
       at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
       at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithFullTrust(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
       at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
       at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
       --- End of inner exception stack trace ---
       at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
       at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
       at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
       at System.Configuration.ConfigurationManager.GetSection(String sectionName)
       at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
       at System.Data.Common.DbProviderFactories.Initialize()
       at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
       at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
       at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
       at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
       at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
       at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
       at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
       at IPDAS.Model.IPDASEntities.SetCommandTimeOut(Int32 timeout)
       at IPDAS.Model.IPDASEntities..ctor(String efConnString)
       at IPDAS.DomainModel.Repository.ConfigDataListRepository.GetConfigDataListList(String listName)

    The application runs great on development box, but error occurs on server box.

    Please help

    Thursday, February 19, 2015 10:43 PM

Answers

  • Hello Bill,

    >>The application runs great on development box, but error occurs on server box

    Feeling a bit confused why the exception occurs at System.Globalization.CultureInfo.() while you are using Entity Framework. After searching more against this exception, it seems this is due to the compare method since there a compare operation in the query. To narrow down this, I suggest that you could write a query without any condition as below to see if it works:

    List<ConfigDataList> conDataListList = ctx.ConfigDataLists. ToList();

    As you mentions, it could be an environment issue since it could work on your development box. For this, please check if there are features are different between the two boxes as the installed .NET Framework version and here is a similar thread:

    https://social.msdn.microsoft.com/Forums/en-US/c97c5dbe-6b5c-42f4-85ed-3ca2ab23d1ba/method-not-found?forum=vstsdb

    It shows this exception is caused by the leaking of .NET framework SP1.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 20, 2015 3:28 AM
    Moderator