Unhandled EntityCommandExecutionException

6 posts, 0 answers
  1. Uwe
    Uwe avatar
    49 posts
    Member since:
    Sep 2012

    Posted 20 Sep 2013 Link to this post

    Hello Telerik,


    I am using version 2013.2.724.40 and I have the following problem. I’m working on an MVVM WPF application. It is a multi-thread application which draws data form a postgres db, displays the data and writes them in to a SQL EXPRESS DB. In one (two) View(s) the data can be displayed and manipulate in a RadGridView this is directly bound to a QueryableEntityCollectionView<>, I’m using the Microsoft Entity Framework.


    Occasionally and absolutely not reproducible, but nonetheless too often I get an unhandled EntityCommandExecutionException, mostly when the user push a button to change the View. The Inner Exception is "A severe error occurred on the current command.  The results, if any, should be discarded.". If this occurs in the Debugger and when I have a look at the stack, it looks like in the attached picture.


    I have the suspicion that comes from the QueryableEntityCollectionView<> bound to the RadGridView, but I have no idea how to prevent this and/or on which place I should enclose some code with a try catch block.
    As you can see in the stack none of my functions or classes are involved.


    May be someone have an idea.


    Regards Uwe

  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Sep 2013 Link to this post

    Hi,

    The exception comes from Entity Framework (in fact from SQL Server, which in your case is not even SQL Server but postgre) when asked about the Count of a query and our collection is not responsible for it in any way.

    What QueryableEntityCollectionView<T> does is simply add Where and OrderBy clauses to your LINQ query so that you don't have to do this by hand. I other words, it knows how to read for example RadGridView.FilterDescriptors and based on the information stored in them build a Where clause like this:

    var results = this.objectContext.Customers.Where(customer => customer.Name == "John");

    It does nothing more than appending Where and OrderBy clauses to your query, so it is responsible for this EF exception.

    What I can see from the stack trace is that your EF layer is throwing this exception when asked about the Count of a query. The count is needed for operations such as paging. So basically, what our collection does is something like this in pseude-code:

    var customersCount = this.objectContext.Customers.Count();

    This where Entity Framework throws your exception. I googled around and it appears that this exception come all the way from your database server, but I cannot tell you why since I am not an EF/DB specialist.

    StackOverflow discusses this same exception in many threads. You can see whether someone else was using EF with PostGre and got similar problems.

    Regards,
    Rossen Hristov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Uwe
    Uwe avatar
    49 posts
    Member since:
    Sep 2012

    Posted 25 Sep 2013 Link to this post

    Hello Rossen,

    thank you for trying to help. 
    The GridView is only assign to the SQL EXPRESS DB using the EF. To get data from the Postgres DB I'm using to different Dlls (Mono.Security.dll and Npgsql.dll) and not the EF, I wrote some own DB function as I need it. 
    As far as I can see (Exception3.png and StackException3.png) the Exception comes from the MS SQL Client through some Dlls, inter alia, through the Telerik.Windows.Data.dll and last but not least to my Main function, without going through any other function of my code.
    This is the point I do not understand and makes me a little bit helpless. 

    Greeting Uwe
  4. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Sep 2013 Link to this post

    Hello,

    The only information that I can extract from this stack trace is the following:

    Our collection asks your query for its Count() and it throws an exception when being asked about its Count().

    This is seen in the blue circle that you have made. We simply call the Count() method on your IQueryable. 

    See: this is the method.

    When we call the Count method of your query -- it throws an exception which is beyond me, really.

    It is your queryable that throws the exception -- not our components.

    Can you please try to ask your query about its Count() without the QueryableEntityCollectionView? In other words -- remove absolutely all Telerik controls from your project and do something like this:

    var customersCount = this.objectContext.Customers.Count();

    I don't know what your real names and entities are so I am using the Customer class as an example. Most probably your entity set name is something different from Customer.

    Please, let me know how can I be of any further assistance related particularly to Telerik controls.

    Regards,
    Rossen Hristov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Uwe
    Uwe avatar
    49 posts
    Member since:
    Sep 2012

    Posted 25 Sep 2013 Link to this post

    Hello Rossen,

    I do as you proposed:

                int Count;
                Count = ((MSSQLAccess.APOSEntities)OC).BAMeasurements.Count();
                Count = ((MSSQLAccess.APOSEntities)OC).Suppliers.Count();
                Count = ((MSSQLAccess.APOSEntities)OC).FuelTypes.Count();

    I take all the entities which come into question, but nothing unusual happens. Count() returns just the the number of records in the SQL table.
    I understand you right: the Telerik.Windows.Data.dll dose nothing else as the code above?

    I am thinking about to use the Telerik OpenAccess Framwork instead of the EF fom MS for the SQL EXPRESS Server. May be it plays better withe the GridView. What is your recommendation?




     
  6. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 26 Sep 2013 Link to this post

    Hi,

    In fact it does not matter whether you use EF or OpenAccess, since the only touching point between RadGridView and both ORM mappers is the IQueryable interface which is a standard .NET interface that our grid respects.

    I have been researching your case and here is what I found. Just like in your case, people reporting this error claim that it happens from time to time and not always. Another possible reason might me the multi-threaded architecture of your application, i.e. connections being opened and closed from different threads. Also, I "guess" that if multiple threads access the same ObjectContext/DbContext such problems might occur.

    There are dozens of similar posts on StackOverflow each reporting the same exception you get. Since you are more acquainted with your project, you might be able to tell which of the StackOverflow cases relates to your particular scenario. But if I had to bet about the culprit I would bet on the multi-threaded stuff. If you could only test your app without the multithreading and see whether this exception is gone, you will have a lead to follow.

    I hope you manage to resolve this problem.

    Regards,
    Rossen Hristov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top