Search code examples
c#sql-server-2008r2-express

SQL exceptions for specific error conditions


I want to know SQL exception (state) for the

"Duplicate Error Record"
"Null Value"

What are the sql exception (state) for above ?

Any suggestion

 enum FilterMode 
    {
        System_AllData = -1,
        System_Error = -2,
        System_DuplicateError = 3,
        System_NullValues = 2,
    }

    private FilterMode SetFilter(string str) 
    {          
        if (str == "All Record")
            return FilterMode.System_AllData;
        else if (str == "All Error Record")
            return FilterMode.System_Error;
        else if (str == "Duplicate Error Record")
            return FilterMode.System_DuplicateError;
        else if (str == "Null Value")
            return FilterMode.System_NullValues;
        else return FilterMode.System_Error;
    }

Solution

  • You can find an extensive list of error messages here, or you can execute this query to get the ultimate master list of all messages in your SQL Server:

    SELECT * 
    FROM sys.messages
    

    Using a suitable WHERE clause, I'm sure you can find the ones you're interested in.