[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2467
  • Last Modified:

User Friendly Timeout Message for SQL Server (0x80040E31)

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
the69void
Asked:
the69void
1 Solution
 
Nitin SontakkeDeveloperCommented:
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
 
jerry2yuCommented:
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
 
Göran AnderssonCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
the69voidAuthor Commented:
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
 
Göran AnderssonCommented:
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
 
the69voidAuthor Commented:
The database guy improved the store procedure .... and I extended the connection time...   Thank you for your assistance.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now