tags:

views:

397

answers:

8

when i run queries to the database im constantly getting this

System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Generated: Tue, 18 Aug 2009 08:05:39 GMT

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Data.Linq.Provider.BindingList.Create[T](DataContext context, IEnumerable`1 sequence)
   at System.Data.Linq.DataQuery`1.GetNewBindingList()
   at System.Data.Linq.DataQuery`1.System.ComponentModel.IListSource.GetList()
   at System.Windows.Forms.CurrencyManager.SetDataSource(Object dataSource)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.get_Item(Object dataSource)
   at PlexityHide.GTP.TimeItemDataConnect.Wire()
   at PlexityHide.GTP.TimeItemDataConnect.UpdateDataSource(IListSource aDataSource, String aDataMember, Layer aLayer)
   at PlexityHide.GTP.TimeItemDataConnect.set_DataSource(Object value)
   at PlexityHide.GTP.Layer.set_DataSource(Object value)
   at WebSchedule._Default.Grid_OnEachListItemWhenDataBound_GridNode(Object GTPComponent, EachListItemWhenDataBoundArgs e) in C:\MyDev\WebSchedule\Schedule.aspx.cs:line 503
   at PlexityHide.GTP.Grid.NodeChangedInDS(GridNode aNode)
   at PlexityHide.GTP.NodeDataConnect.UpdateRowContent(Int32 index)
   at PlexityHide.GTP.NodeDataConnect.EnsureBindUpToDate()
   at PlexityHide.GTP.GridNodes.get_Count()
   at PlexityHide.GTP.GridStructure.get_FirstVisibleNode()
   at PlexityHide.GTP.Gantt.set_TurnOffAllCollisionDetect(Boolean value)
   at PlexityHide.GTP.WEB.Gantt_ASP.OnPreRender(EventArgs e)
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.BasePartialCachingControl.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   --- End of inner exception stack trace ---
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.schedule_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\13c4fe72\f906a8a8\App_Web_schedule.aspx.cdcab7d2.nhap4sin.0.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

could it be caused by the number of connections that are going to the database at anyone time? the page in question calls a gantt chart and populates it with the data from a schedule table per a specific contract. and what is happening is that if say 10 people are making the call to the table at the same time i get the timeout happening

+3  A: 

the work you are trying to do takes longer than the default time out period. your query is running too slow. it may be this query, another query slowing everyone else down, updates blocking, or a number of reasons.

KM
A: 

Likely your statement is taking too long. If it is only happening with multiple users, look for locking that might be freezing up resources. Use "with(nolock)" if possible.

IPX Ares
A: 

Check how long it takes when you run the same query in query analyzer.

Look at the query plan.

Use Profiler to check if there are multiple connections and time taken for this stored proc in question.

Check the command time out in ADO.NET.

CodeToGlory
A: 

This is the client timeout, so if the database is heavy used (many connections/large queries) and is not able to respond in specified amount of time, the client will eventually throw an exception.

Try incising the query timeout, or look at the Profiler to optimize the query.

Pawel Lesnikowski
+5  A: 

It's possible that you've got too many long-running queries. Another very likely cause is that you're not closing the connections as soon as you've finished with them, which releases them to the connection pool.

In general, you should acquire connections as late as possible and release them as early as possible with a using statement, to avoid just this kind of situation. If you don't close the connection explicitly (even in the face of exceptions) you're putting yourself at the mercy of the garbage collector and finalizers to return the connection to the pool.

If you believe you genuinely have many active connections with long-running queries, you should increase the number of connections in the connection pool. If you believe it's the actual query itself timing out (i.e. taking longer than you're allowing) then you should increase the timeout for the command or connection.

Jon Skeet
A: 

Not being able to see your query or data structure we can only offer guesses at what could be causing your time out. In most cases the query is to slow. Increasing the Timeout period for your connection can get around the time out issue but it is usually best to fix your query. The other thing to take a look at is the indexes of the tables your query is hitting against. If you have a lot of joins in your query then your indexes should incorporate the fields you are joining on.

VBCSharp
A: 

In my experience, it's almost always the query.

Open up the query in Query Analyzer or Management Studio and find the estimated execution plan. My rule of thumb is that an often-executed query should have a cost less than 1.00. If it starts getting past 2.00, you'll start seeing problems. (Of course, this was specific to my site where there were several other problems...).

If your query costs are already low, run the Profiler to see what other commands are hitting the server. Then start analyzing those queries to find the expensive ones.

If it tends to happen at certain times of the day, check these:

  • Is a backup process running and taking longer than normal?
  • Is there a scheduled report running that is blocking (a bad query)?
  • Are you overwhelming it with connections? Especially after a few hours of running, you could have a bug with your connection management where you are leaving connections open.
Austin Salonen
A: 

What isolation level are you using?

Are you using a connection pool?

If its ok to do a dirty read, make sure your isolation level is uncommited read.

Knife-Action-Jesus
no im not using a connection pool
kevinw
what are your timeouts set to?Check both Connection and Commandhttp://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspxhttp://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx
Knife-Action-Jesus