Linq-to-SQL Timeout Linq-to-SQL Timeout asp.net asp.net

Linq-to-SQL Timeout


Just found the answer playing with intellisense:

using (MainContext db = new MainContext()){    db.CommandTimeout = 3 * 60; // 3 Mins}

This is how you can increase the time out for a query on a per query basis as supposed to modifying the connection strings or data contexts.


@Tom Gullens answer didn't work for me on EF6

I had to drill down to Database on DbContext

Ecom.Database.CommandTimeout = 120;

Hope this saves you some time.


Here is the latest syntax for .Net 4.5.

    MyDbContext context = new MyDbContext();    context.Database.SetCommandTimeout(300);