This project is read-only.

Problem setting connection timeouts

Jul 6, 2012 at 3: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

  <connectionStrings>
    <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" />
  </connectionStrings>

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

Many thanks for any help

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

Does this perhaps relate to this http://stackoverflow.com/questions/6232633/entity-framework-timeouts ?

If so and you need to get the EF context it describes how in the manual (or here http://nakedobjects.codeplex.com/discussions/275627 )

Jul 6, 2012 at 4: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 4:55 PM
Edited Jul 6, 2012 at 4: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 5:37 PM

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