Solved

User Friendly Timeout Message for SQL Server (0x80040E31)

Posted on 2002-05-28
6
2,309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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