Solved

User Friendly Timeout Message for SQL Server (0x80040E31)

Posted on 2002-05-28
6
2,248 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 6

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select TOP 5 COUNT(*) 13 55
Highlight a word from some text 16 42
classic asp checkbox uncheck and check 2 49
Pass through dll 2 38
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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now