Close Database Connection when an Error occurs on

Results 1 to 4 of 4

Thread: Close Database Connection when an Error occurs on

  1. #1
    Shonda Hector Guest

    Default Close Database Connection when an Error occurs on

    I was warned by my Web Hosting Service that I must always issue a command to close my Database Connection. But, what happens when an error occurs on my ASP page after the connection has already been opened and prior to reaching the command to close the Database Connection? Is there an OnError command that I should use (VBScript)?

  2. #2
    Join Date
    Dec 1969

    Default ASP 2.0 "On error resume next" there is a whole

    new error object introduced in ASP 3.0 the "ASP Error Object" not that you wouldnt be able to use On error resume next.

  3. #3 Guest

    Default On Error Resume Next

    If you use the command "On Error Resume Next" and it will prevent errors from showing up on your production site. However it is not as simple as that, because you must then check the error code at many places in your code, otherwise you are likely to have pages showing gibberish or nothing. You need to check your code to determine all the things that could go wrong, and you then need to write code to check for all forseeable mishaps. Take the example of openning a recordset and reading it into an array:<BR><BR>You would probably be filtering according to some criterion. So before you execute the rs check that the filter is correct. If the field is [ID] and filter "where [ID] = " & IDValue, then if IDValue is blank or a non-numeric string, you will get a syntax error, because the filter evaluates to "where [ID] = ". OK so you ceck that IDValue is non-null & numeric, and execute, but the IDValue does not exist. You would get a blank recordset and when you use the GetRows to read it into an array, you get an error due to EOF. <BR><BR>First of all you could prevent these errors by checking the value of IDValue, and checking if you got any records back from the query, but being human, you forget one of the checks. So you put "on error resume next" in, and you never see any errors. You could check the system variable Error or Err after critical operations. It would be a good idea to remove these statements in your testing/development environment so that all errors are seen before you release your code.<BR><BR>Anyway lookup the On Error command in MSDN, and also ADO Error object to see errors within the ADO.<BR>

  4. #4
    Sreedharan Guest

    Default Improper use of On Error Resume Next

    If you want to close your database connection, there is no use in using On Error Resume Next in your ASP page. That just passes on execution to the next line in your ASP page.<BR><BR>The On Error Resume Next statement is *NOT* meant to cover up mistakes in your code! It is a bad mistake to use it for that! For one, it will prevent you from seeing your mistakes, thus preventing you from correcting them. Secondly, it will make your page much slower. <BR><BR>You should use On Error Resume Next in certain conditions like when you use some objects which may give an error in certain cases, which *YOU* may not be able to handle.<BR><BR>The best case would be a create a COM object, which connects to the database, does the work, and closes the connection before passing the result to the web page. That is pretty easy to do, and will also standardize your database access. Also, say suppose you create the object using VB, you can manipulate it that much better.

Posting Permissions

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