473,378 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to identify whether an SQLException is TimeOUtException or not?

Hi,

In my application.... i want to identify whther the SQLException caught is a Timeout or any other SQLException. The reason being, i have to show a different msg to the user in case it is a timeout error.

Thank you in advance
Feb 28 '08 #1
2 1833
kenobewan
4,871 Expert 4TB
Are you using framework 2.0? Have you identified error numbers for these?
Feb 28 '08 #2
When a SqlException occurs you can loop through the errors and get the error code for the Exception

Expand|Select|Wrap|Line Numbers
  1. catch (SqlException ex)
  2. {
  3.     foreach(SqlError error in ex.Errors)
  4.     {
  5.         // error.Number
  6.     }
  7. }
  8.  
If the error occurs duing a connection, this number will represent a socket error, such as 10060 for "An error has occurred while establishing a connection to the server." Otherwise if you are executing a sql command, this correspond to an error on your Sql Server. You can find all the errors by querying the master.dbo.sysmessages table, and error 17197 corresponds to "Login failed due to timeout"

Hope this helps.
Feb 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
0
by: darjonase | last post by:
Alright, here is my issue. I am using the IO.Ports.SerialPort namespace for the following method. In a previous method, I already set the serial port up using the proper baudrate, parity, etc. ...
6
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.