Handling various types of SQLException in C#

I had a usual scenario of handling various SQLExceptions and I found that there is in fact a very nice table which holds a list of all such scenarios.You just need to run the following query in your master DB.

SELECT * FROM sysmessages

And you can handle the errors in the C# side by looking into the Number property for SQLException.

try
{
}
catch (SqlException exception)
{
if (exception.Number == 2601)
{
//Ignore.Its ok I can live with this!
}
else
throw;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s