locked
MS Lightswitch - How to set TimeOut for connection RRS feed

  • Question

  • I am using Microsoft Lightswitch with Silverlight client. I am facing timeout error after 30 seconds. I am unable to change this. I tried to change in web.config but it makes no effect. And within C# screens code, there is also no way to change this in DataWorkspace.ApplicationData.

    Also tried Application_Initialize event to set timeout:

    this.Details.ClientTimeout = 100000;
    But still getting timeout error after 30 seconds.

    Is there any way to change timeout for lightswitch applications. Application is hosted in IIS.


    Muhammad Idrees


    • Edited by M Idrees Saturday, November 7, 2015 12:15 PM
    Saturday, November 7, 2015 9:49 AM

Answers

  • The only way I found was using the underlying Entity Framework ObjectContext. This code runs on the server and is called by WebAPI.

    //Using EF lets us specify the .Includes to eager-load our required data, in a single roundtrip!
    //EF also lets us access the FK attributes hidden by the Lightswitch entity objects.
    //Need to supply the Entity Framework connection string.
    using (LightSwitchApplication.Implementation.RealEstateData objectContext =
          new LightSwitchApplication.Implementation.RealEstateData(this.EFConnectionString))
    {
        objectContext.CommandTimeout = 90;
        //... do your work...
    )

    • Edited by Paul23 Monday, November 9, 2015 2:01 PM
    • Proposed as answer by Angie Xu Tuesday, November 17, 2015 1:57 AM
    • Marked as answer by Angie Xu Tuesday, November 17, 2015 1:57 AM
    Monday, November 9, 2015 2:01 PM

All replies

  • The only way I found was using the underlying Entity Framework ObjectContext. This code runs on the server and is called by WebAPI.

    //Using EF lets us specify the .Includes to eager-load our required data, in a single roundtrip!
    //EF also lets us access the FK attributes hidden by the Lightswitch entity objects.
    //Need to supply the Entity Framework connection string.
    using (LightSwitchApplication.Implementation.RealEstateData objectContext =
          new LightSwitchApplication.Implementation.RealEstateData(this.EFConnectionString))
    {
        objectContext.CommandTimeout = 90;
        //... do your work...
    )

    • Edited by Paul23 Monday, November 9, 2015 2:01 PM
    • Proposed as answer by Angie Xu Tuesday, November 17, 2015 1:57 AM
    • Marked as answer by Angie Xu Tuesday, November 17, 2015 1:57 AM
    Monday, November 9, 2015 2:01 PM
  • This technique does not seem to be supported in VS2013 it must have been available in an earlier version. It was a good seed for a partial VS2013/2015 solution. We really need to be able to adjust the command timeout when working with Azure SQL as workload latency seems to be very non deterministic.

    For VS2013/2015, create a class in your Server project called say ApplicationData.cs and paste the following code in it:

    using System.Data.Objects;
    
    namespace LightSwitchApplication.Implementation
    {
        public partial class ApplicationData : ObjectContext
    	{
    		partial void OnContextCreated()
    		{
    			CommandTimeout = 120;
    		}
    	}
    }
    
    Unfortunately, this sets the command timeout to 120 seconds for all ApplicationData ObjectContext creations. It would be nice to specify the timeout for each Entity Insert/Update/Delete/Query.

    • Proposed as answer by SimorC Thursday, November 12, 2015 1:10 AM
    Tuesday, November 10, 2015 8:10 AM
  • Hi,

    You do it in the deployment process:


    Sven Elm

    Wednesday, November 11, 2015 12:35 PM
  • Hey Sven,

    Yes, you have access to the Connect Timeout but this is different than the Command Timeout.

    The Connect Timeout is the amount of time to wait for a connection to a SQL Server.

    Command Timeout is the amount of time to wait for a Query/Update/Insert and this is after a Connection is made to SQL Server.

    In my case, I need the Command Timeout increased for specific reports that query a large data set. 

    Wednesday, November 11, 2015 12:48 PM
  • Hi Ian,

    Thank you for posting this.  A couple dumb questions:  

    The partial class needs to be for the particular dataservice you want to extend, correct?  So, ApplicationData would be for the intrinsic datasource and you would use <YourDataSource> to extend the timeout of an external datasource?

    What do you use to test the timeout?  Thread.Sleep()?

    Thanks again.

    Wednesday, November 11, 2015 4:46 PM
  • You can add one for each data service.

    I test first by putting a breakpoint and running my report/query etc and make sure the breakpoint is hit. Unfortunately, the only way to really real test is with an actual load.

    Cheers

    Thursday, November 12, 2015 12:47 AM
  • I test by setting a timeout of 3 seconds, verifying that it times out, and then increasing the timeout as needed.

    Paul

    Friday, November 13, 2015 1:55 PM