Print Page | Close Window

Error: The query has been canceled because

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums
Forum Description: Support forum for Web Wiz Forums application.
URL: https://forums.webwiz.net/forum_posts.asp?TID=23675
Printed Date: 07 April 2026 at 9:38am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Error: The query has been canceled because
Posted By: Cem Alacayir
Subject: Error: The query has been canceled because
Date Posted: 04 July 2007 at 9:15pm

Microsoft OLE DB Provider for SQL Server error '80040e14'
The query has been canceled because the estimated cost
of this query (432) exceeds the configured threshold of 60.
Contact the system administrator.

 
I started to get the above error whenever I deleted a single post from a topic. The post was really deleted but the error was causing topic records to be orphaned thus the topics were disappearing from the forums. I found out that the delete query was successfull but another query just before the query that updates topic statistics was stopping the execution in delete_post.asp.
 
The query that was failing is
 

 'Check there are other Posts for the Topic, if not delete the topic as well 
 'Initalise the strSQL variable with an SQL statement to get the Threads from the database
 strSQL = "SELECT " & strDbTable & "Thread.Thread_ID " & _
 "FROM " & strDbTable & "Thread" & strDBNoLock & " " & _
 "WHERE " & strDbTable & "Thread.Topic_ID = "  & lngTopicID & " " & _
 "ORDER BY " & strDbTable & "Thread.Message_date ASC;"
 
 'Query the database
 rsCommon.Open strSQL, adoCon
 
 
 'If there are posts left in the database for this topic get some details for them
 If NOT rsCommon.EOF Then
  
  'Move to the last message in the topic to get the details of the last post
  rsCommon.MoveLast
  
  'Get the post ID of the last post
  lngLastPostID = CLng(rsCommon("Thread_ID"))
 End If
 
 'Close the recordset
 rsCommon.Close
 
It seems strange to me that a simple task like finding the last post id of the thread is determined with an inefficient code like this which costs too much in SQL Server. So I changed the code to a better version:
 

 strSQL = "SELECT MAX(" & strDbTable & "Thread.Thread_ID)" & _
 "FROM " & strDbTable & "Thread"  & strDBNoLock & " " & _
 "WHERE " & strDbTable & "Thread.Topic_ID = "  & lngTopicID
 rsCommon.Open strSQL, adoCon
 If NOT rsCommon.EOF Then
  If (rsCommon(0) <> "") Then lngLastPostID = CLng(rsCommon(0))
 End If
 rsCommon.Close
 
 
I hope Borg optimizes queries like this in version 9.0.



Replies:
Posted By: WebWiz-Bruce
Date Posted: 05 July 2007 at 9:07am
I think this page got missed in the last optimisation audit, but will certainly look at improving it.

I have a feeling though that for mySQL the MAX method is a bit buggy when you include a WHERE clause.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: WebWiz-Bruce
Date Posted: 05 July 2007 at 9:12am
The following should have the same type of performance improvement, but will ensure compatibility with all databases types used:-

strSQL = "SELECT " & strDBTop1 & " " & strDbTable & "Thread.Thread_ID " & _
    "FROM " & strDbTable & "Thread" & strDBNoLock & " " & _
    "WHERE " & strDbTable & "Thread.Topic_ID = "  & lngTopicID & " " & _
    "ORDER BY " & strDbTable & "Thread.Message_date ASC " & strDBLimit1 & ";"



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: Cem Alacayir
Date Posted: 05 July 2007 at 11:30am
Yes, this seems like a better version.
 
I don't know why but it seems "ORDER BY Thread.Message_date" costs too much in SQL Server for some reason but using strDBTop1 should improve it.
 
Thanks Borg.


Posted By: WebWiz-Bruce
Date Posted: 05 July 2007 at 11:41am
Not sure why it wasn't like that in the first place, seems stupid returning all the records then using a client side recordset move, when all we need is the 1 record.

-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net