Database Related Error Handling in ASP

Results 1 to 2 of 2

Thread: Database Related Error Handling in ASP

  1. #1
    Join Date
    Dec 1969

    Default Database Related Error Handling in ASP

    Hi,<BR> I am working with ASP and SQL Server as the database. During Database actions, whenever I get a database error (For example, null handling, constraints like primary, foreign key ), I am not able to track the error number from the database and show a corresponding customized error message in the ASP Page.<BR><BR>Please suggest me a method to solve this problem.<BR><BR>An earlier solution of this problem is very much appreciable.<BR><BR>If possible, please mail the solution to <BR><BR><BR><BR>Thanks,< BR>Amar<BR>

  2. #2
    Join Date
    Dec 1969

    Default Pretty easy

    First off all, I never send email but I always post the answers on this board, so other people might learn something from it also.<BR><BR>The database generated errors are appended to the connection or command object errors collection. So when you use:<BR><BR>Set MyRecordSet = MyConnection.Execute (some SQL Code)<BR><BR>and there were errors in the db operation you can check them with<BR><BR>IF MyConnection.Errors.Count &#062; 0 THEN <BR> FOR EACH oops IN MyConnection.Errors<BR> Response.Write Oops.Number<BR> &#039;Custom error handling based on the error number<BR> NEXT<BR>END IF<BR><BR>Be sure to use MyConnection.Errors.Clear before you execute a statement to clear any errors from a previous command.<BR><BR>When you use the ADODB Command object, the errors are appended to the MyCommand.Errors collection.<BR><BR>When you use SQL Server, warnings (e.g. Warning: NULL value eliminated from aggregate) are also appended to the Errors collection.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts