Experts Exchange connects you with the people and services you need so you can get back to work.
// Statement which can cause an exception.
// Statements for handling the exception
//Any cleanup code
Open in new window
public static void ShowSqlException(string connectionString)
string queryString = "EXECUTE NonExistantStoredProcedure";
StringBuilder errorMessages = new StringBuilder();
using (SqlConnection connection = new SqlConnection(connectionString))
SqlCommand command = new SqlCommand(queryString, connection);
catch (SqlException ex)
for (int i = 0; i < ex.Errors.Count; i++)
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.