Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:48:18+00:00 2026-06-13T12:48:18+00:00

I need to be able to test whether a System.Data.SqlClient.SqlException is due to a

  • 0

I need to be able to test whether a System.Data.SqlClient.SqlException is due to a network error or not (.NET environment connecting to MS SQL Server). If it is, I can tell the user that there is a problem with his connection, whereas if it is not, it is most likely a bug in my code which is to be treated differently. Obviously, it is crucial not to have false positives (declare somehting a network problem when it is a bug).

In a related question over here it was suggested to extract the information from the exception text. This is ugly and difficult in my case, since the text is localized, and might be different depending on the environment.

For the time being, I examine the call stack for certain function calls, which (by experience) are associated with network problems:

System.Data.SqlClient.TdsParserStateObject.WritePacket
System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket
System.Net.Sockets.SocketException

However, none of these pops up if there is a timeout while executing, for instance, a SELECT query. So there, I would have to revert to checking whether “Timeout” appears in the exception message, which is ugly.

Does anyone out there have a better idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:48:19+00:00Added an answer on June 13, 2026 at 12:48 pm

    Parsing the error message and stack is the last thing you want to do.

    SqlException comes with a collection of Errors.
    By inspecting the SqlError.Number, SqlError.State and the SqlException inner exception you can make a good guess whether the exception is local (ie. network) or remote (ie. on server). Error numbers above 100 will be most likely reported by server. Error numbers -2, -1, 2, and 53 are know to be client side errors. Exceptions that contain an inner Win32Exception are also client side. MSDN contains this decision table to help.

    As a side note: timeout is not a server error, there is no such concept as query timeout in SQL Server. Timeouts are triggered by your own application because of the default 30 seconds of SqlCommand.CommandTimeout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the need for a function in C# that will test whether a string
I'm writing some unit tests and I need to be able to Assert whether
I'm very new to Symfony2 and I need to be able to test the
Easy question this time. I'm trying to test whether or not a string does
I need to be able to test if $post_count is equal to any number
I have two workbooks with identical sheets and I need to test whether the
I need to be able to test and see if a directory exists on
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to access a list throughout my Rails project. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.