home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _2c007e7b03ffdcf6ae2238803dd11761 < prev    next >
Text File  |  2004-06-01  |  2KB  |  67 lines

  1. <%@ LANGUAGE = PerlScript%>
  2. <html>
  3. <head>
  4. <meta name="GENERATOR" content="Tobias Martinsson">
  5.  
  6. <title>ADO Error Checking</title>
  7. </head>
  8. <body>
  9. <BODY BGCOLOR=#FFFFFF>
  10.  
  11. <!-- 
  12.     ActiveState PerlScript sample 
  13.     PerlScript:  The coolest way to program custom web solutions. 
  14. -->
  15.  
  16. <!-- Masthead -->
  17. <TABLE CELLPADDING=3 BORDER=0 CELLSPACING=0>
  18. <TR VALIGN=TOP ><TD WIDTH=400>
  19. <A NAME="TOP"><IMG SRC="PSBWlogo.gif" WIDTH=400 HEIGHT=48 ALT="ActiveState PerlScript" BORDER=0></A><P>
  20. </TD></TR></TABLE>
  21.  
  22. <HR>
  23.  
  24. <H3>ActiveX Data Objects (ADO) Errors</H3>
  25. Whenever an error during the database session occurs, the Errors collection of the Connection object is where you need to go. It contains a group of Error objects that you can examine in order to understand the error. However, this is not the same as detecting an error -- although closely related. The "count"-property of the Errors collection returns the number of Error objects present, thus you use it best to detect errors.
  26.  
  27.  
  28.     <p>
  29.     <%
  30.         # Create an instance of a Connection object
  31.         #
  32.     $conn = $Server->CreateObject("ADODB.Connection");
  33.  
  34.         # Open it by providing a System DSN as the parameter
  35.         #
  36.     $conn->Open( "ADOSamples" );
  37.  
  38.         # Deliberately cause an error by typo'ing the query
  39.         # 
  40.         $conn->Execute( "ZELKECT * FROM Orders" );
  41.  
  42.     if($conn->Errors->{Count} > 0) {
  43.         $Response->Write("There's been an error ...");
  44.         $Response->Write($conn->Errors(0));
  45.     }     
  46.  
  47.         $conn->Close(); # Close the connection
  48.         undef($conn); # Destroy the object
  49.     %>
  50.  
  51. <!-- +++++++++++++++++++++++++++++++++++++
  52. here is the standard showsource link - 
  53.     Note that PerlScript must be the default language --> <hr>
  54. <%
  55.     $url = $Request->ServerVariables('PATH_INFO')->item;
  56.     $_ = $Request->ServerVariables('PATH_TRANSLATED')->item;
  57.     s/[\/\\](\w*\.asp\Z)//m;
  58.     $params = 'filename='."$1".'&URL='."$url";
  59.     $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
  60. %>
  61. <A HREF="index.htm"> Return </A>
  62. <A HREF="showsource.asp?<%=$params%>">
  63. <h4><i>view the source</i></h4></A>  
  64.  
  65. </BODY>
  66. </HTML>
  67.