1

We are using Linq to connect the database and in one situation we need to execute the big query and I can execute that query directly in sql server, but when I was trying to execute the same query through asp.net it was showing timeout error, can you help me?

Also we are using pagemethods => webmethods to contact the sql server.

https://i.stack.imgur.com/iohRx.png

Peter
  • 3,916
  • 1
  • 22
  • 43
Merbin Joe
  • 611
  • 6
  • 27

2 Answers2

0

You need to increase the CommandTimeout, not ConnectionTimout. ConnectionTimeout (In other answer) is the amount of time the app allows to connect to the DB rather than run a comment.

You probably also want to look into improving the performance of your sql query by adding indexes etc. You could use SQL profiler to catch the sql statement that Linq to SQL generated. Grab the query and run it through an execution plan on SSMS and see where it's taking most time to execute. This is generally a good place to start.

Darren Gourley
  • 1,798
  • 11
  • 11
  • we are not using commands, instead of this we are using linq. In linq how can we increase the timeout? – Merbin Joe Nov 11 '15 at 11:21
  • Yea, but Linq to SQL transforms the expression to SQL which in turn is sent through to the DB. Check out this article: http://www.codeproject.com/Articles/26283/Change-The-Default-CommandTimeout-of-LINQ-DataCont – Darren Gourley Nov 11 '15 at 11:23
0

Have a look at the answer to this question: Linq-to-SQL Timeout

You can set the command timeout on your DataContext object (https://msdn.microsoft.com/library/system.data.linq.datacontext.commandtimeout%28v=vs.110%29.aspx).

Example (from the linked answer):

using (MainContext db = new MainContext())
{
    db.CommandTimeout = 3 * 60; // 3 Mins
}
Community
  • 1
  • 1
Peter
  • 3,916
  • 1
  • 22
  • 43