0

If I have ORA-12899 returned from an insert or update statement. How can I extract the column name from the OracleException without parsing the string?

ORA-12899: value too large for column "SCHEMA"."TABLENAME"."COLUMNNAME" (actual: 175, maximum: 23).

I would like to do something like this:

try
{
    // Insert code.
}
catch (OracleException orclEx)
{
    if (orclEx.Number == 12899)
    {
        string columnName = GetColumnName(orclEx);
        throw new Exception(columnName + " value is too long.", orclEx);
    }
}
finally
{
    // Finally code
}
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625

1 Answers1

0

I don't know how to do this without parsing the error message. I try to prevent bad data from getting to the database in the first place. So, in an ASP.NET form I use a regular expression validator like this. This one prevents you from passing more than 100 characters. You can type in more than 100 characters, but when you hit the OK or Submit button, it will not process the data until you shorten the input.

In addition, I use a validation summary to display the ErrorMessage.

<asp:RegularExpressionValidator ID="regExpInspectionNotes" runat="server" SetFocusOnError="true" Text="*"  ControlToValidate="txtInspectionNotes" ErrorMessage= "Maximum length of inspection notes is 100 characters." ValidationExpression="^[\s\S]{1,100}$" Display="Dynamic"> </asp:RegularExpressionValidator>

Also, I pass the values to a stored procedure and do the update using PL/SQL.

As far as parsing the error message, it really wouldn't be too difficult to get the column name by parsing.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Harv
  • 523
  • 3
  • 8