user3314399
user3314399

Reputation: 325

SQL Exception Code

I have been catching the SQL exception codes in C# using:

 catch (SqlException x)
        {
            Console.WriteLine(x.Message.ToString());
            Program.MyLogFile("SQL Upload Failed SQL Exception     ", x.ErrorCode.ToString() +" ", today);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            Program.MyLogFile("SQL Upload Failed All Exeption    ", ex.Message.ToString() + " ", today);
            email();
        }

It gives me the following number in the text file. How can I tell what it means?

Error Code: -2146232060 I am using SQL 2012

Upvotes: 1

Views: 999

Answers (1)

Angel_Boy
Angel_Boy

Reputation: 1028

Consider using the SqlException.Number Property as shown here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.number.aspx

Also this would give better understanding of the error message if you query this in SQL Server if you want to work with one particular error code and do something:

SELECT * FROM sysmessages

If you look at error:104 from the above query and then: Example If theres an error with Union and Order By in sql:

catch (SqlException e)
{
   switch (e.Number)
   {
      case 104:
         // Do something.
         break;
      default:
     throw;
   }
 }

Upvotes: 3

Related Questions