locked
Entity Framework Never Returns RRS feed

  • Question

  • I have a windows service using Entity Framework 4 for data access.  The machine is being hosted on a virtual machine.

    Last night the virtual machine's host was rebooted which caused the virtual machine hosting my service to take a snapshot of the virtual machine.  When the virtual machine's host came back up, the virtual machine restarted and my service restarted as well.

    There were no issues in the service up until he creation of the object context, which never returned.  It sits with no exception of any type.  In this instance, it sat for 7 hours until someone manually restarted the service.  After the manual restart the service came back up fine and the entity framework functioned as normal.

    Can anyone give me any insight into why this might be happening?  Ultimately, if the entity framework is having an issue I'd rather it throw an exception so that the exception can be dealt with.  With the current behavior there is no way to detect that there is a problem.

    Thanks in advance.

    • Moved by Arthur Vickers - MSFT Thursday, December 16, 2010 1:56 AM Not a pre-release question. (From:ADO.NET Entity Framework and LINQ to Entities (Pre-Release))
    Wednesday, December 15, 2010 3:51 PM

Answers

  • Last night the virtual machine's host was rebooted which caused the virtual machine hosting my service to take a snapshot of the virtual machine.  When the virtual machine's host came back up, the virtual machine restarted and my service restarted as well.

    There were no issues in the service up until he creation of the object context, which never returned.  It sits with no exception of any type.  In this instance, it sat for 7 hours until someone manually restarted the service.  After the manual restart the service came back up fine and the entity framework functioned as normal.

     

    Can you reproduce it? E.g. by restarting the VM?

    I'd look at service dependencies and startup order. Maybe your service launched before something that it depends on (SQL Server, MSDTC, or something like that). If you can reproduce it, you can probably narrow down the cause...

    Make sure your exception handling and exception logging is rock solid too. If unhandled exceptions are raised in some of the ServiceBase event handlers, that can lead to funky service behavior. (In other words: it it possible that EF raised an exception but it didn't get handled and logged?)


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4
    Friday, December 17, 2010 4:58 AM

All replies

  • Hello John,

    Thanks for your thread and welcome to EF forum!

    Based on my understanding, you build a windows service application with Entity Framework which was hosted on a virtual machine. However, the service has some issue (“object context never returned with no exception messages”) when restarting the virtual machine. After a manual restart, the service runs normal. If I misunderstand you, please correct me.

    As far as I know, there are several startup types for windows service and windows service will automatically start when starting the machine only if we set the Startup type to Automatic. Do you happen to set the startup type to manual? You can go to the Properties page and check it.

    By default, if there are any exceptions/errors happened in a windows service application, Windows Log will keep a record of it. Please open you windows logs and check if there are any information available.

    Best regards,


    Roahn Luo [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 17, 2010 2:36 AM
  • Last night the virtual machine's host was rebooted which caused the virtual machine hosting my service to take a snapshot of the virtual machine.  When the virtual machine's host came back up, the virtual machine restarted and my service restarted as well.

    There were no issues in the service up until he creation of the object context, which never returned.  It sits with no exception of any type.  In this instance, it sat for 7 hours until someone manually restarted the service.  After the manual restart the service came back up fine and the entity framework functioned as normal.

     

    Can you reproduce it? E.g. by restarting the VM?

    I'd look at service dependencies and startup order. Maybe your service launched before something that it depends on (SQL Server, MSDTC, or something like that). If you can reproduce it, you can probably narrow down the cause...

    Make sure your exception handling and exception logging is rock solid too. If unhandled exceptions are raised in some of the ServiceBase event handlers, that can lead to funky service behavior. (In other words: it it possible that EF raised an exception but it didn't get handled and logged?)


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4
    Friday, December 17, 2010 4:58 AM
  • It did turn out to be an issue with exception handling and it was not related to the Entity Framework or VM.

    I was able to reproduce the error by taking the database offline and restarting the service.

    The process responsible for data access did not have a try/catch around it.  It does raise the question as to why I'm randomly loosing database connectivity, but now at least I'll be able get more detail, properly handle the exception, and keep the service processing.

    Thanks for your help!

    Tuesday, December 21, 2010 5:37 PM