Solved

User Friendly Timeout Message for SQL Server (0x80040E31)

Posted on 2002-05-28
6
2,298 Views
Last Modified: 2008-03-03
I would like capture the timeout error and present a user  friendly message to ask him/her to narrow their search.

I do not want to extend the connection time.  The strangest part of this issue is that it doesn't timeout when I hit back and click the search button again.

This is the error that I receive:
Microsoft OLE DB Provider for SQL Server (0x80040E31)
Timeout expired

thank you for your help

0
Comment
Question by:the69void
6 Comments
 
LVL 7

Expert Comment

by:Nitin Sontakke
ID: 7040637
At the face of it, this doesnot have anything to do with timeout. The fact that it doesn't happen second time.

Have you tried running the query in Query Analyzer directly. See how long it takes there.
0
 

Expert Comment

by:jerry2yu
ID: 7040748
Hi the69void,

Please try something like the following,

       try{
          string strConn;
          strConn="server=sqlserver2.bbc.com;database=***;UID=***;PWD=***;";
          SqlConnection myConn = new SqlConnection(strConn) ;
          myConn.Open();
          String strSQL;
          strSQL = "update userinformation set Company='" + strCompany + "'";          SqlCommand updateCMD = new SqlCommand(strSQL, myConn);
          Int32 _totalRecords = (Int32)updateCMD.ExecuteNonQuery();
          myConn.Close();
          ResultMessage.Text =_totalRecords.ToString() + " record updated successfully.";
      }
     catch (Exception  eException){
          ResultMessage.Text=eException.Message;
     }
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 7042085
You catch the timeout error just as any other database error:

On Error Resume Next
Set rstResult=cnnDb.Execute(strSQL)
If cnnDb.Errors.Count=0 Then
   ' show the result
Else
   ' handle the error
End If
On Error Goto 0
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:the69void
ID: 7043172
I cannot use On Error Resume Next.  Because "it doesn't trap the errors, it lets them run away never to return."
http://www.infinitemonkeys.ws/infinitemonkeys/articles/asp/943.asp

Also, I'm not using ASP.net ... so I'm assuming try/catch would be Javascript which I'm truly weak in.

As for running the store procedure in Query Analyzer... yes it takes awhile depending on the user's parameter.  Regardless of the intermittent time out, which usually occur the first time they try to run the search, all I want is to capture the timeout and ask the to narrow their search.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 100 total points
ID: 7043399
There is no problem in using On Error Resume Next, as long as you only use it where it's needed, and turn the error checking on again.

Atrax is using that example of bad error handling to imply that the error handling of JScript is far better, but I've seen the same fault being made using try...catch also. Bad code can be written in any language, but it doesn't mean that the language is bad.

Although the error handling in VBScript is somewhat awkward, it's still sufficient for writing professional applications.

The thing to remember when you turn the error checking off in VBScript, is that you have to check for errors after every command that can produce one. That's why you should turn on the error checing again as soon as possible.

The error checking is turned on again with:
On Error Goto 0

Also, if you turn the error checking off inside a sub or function, it's turned on again when you leave it.
0
 

Author Comment

by:the69void
ID: 7112550
The database guy improved the store procedure .... and I extended the connection time...   Thank you for your assistance.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question