Problem setting connection timeouts

Jul 6, 2012 at 2:38 PM

Using NO in a pilot development, I have database retrieval actions that take some time to complete (because the DB server is very slow).

I expected to be able to change the connection timeout (to 0 to set unlimited) in the connection strings in Web.Config & App.Config files as in

    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
    <!-- Add Your connection string here -->
    <add name="SWPDA_DBEntities1" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=SWPDA_DB;integrated security=True;Connection Timeout=0;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Sadly this has no effect. Can anyone advise me please?

Many thanks for any help

Jul 6, 2012 at 2:58 PM
Edited Jul 6, 2012 at 2:59 PM

Does this perhaps relate to this ?

If so and you need to get the EF context it describes how in the manual (or here )

Jul 6, 2012 at 3:35 PM

Thanks for the pointer. Where would you suggest is the best place to hook the timeout setup (context.CommandTimeout = 0;)

Jul 6, 2012 at 3:55 PM
Edited Jul 6, 2012 at 3:57 PM

Off the top of my head I'd probably write a little helper something like ...

public static class Helper { public static IQueryable<T> ResetTimer<T>(this IQueryable<T> queryable) { ObjectContext context = ((ObjectQuery)queryable).Context; context.CommandTimeout = 300000; return queryable; } }


and then attach it to the relevant queries...


 return Container.Instances<MostSimple>().ResetTimer().First();
Jul 6, 2012 at 4:37 PM

Thanks for that guidance, I now have a working system, without timeout errors!