<%@ LANGUAGE = PerlScript%> ADO Error Checking
ActiveState PerlScript

ActiveX Data Objects (ADO) Errors

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.

<% # Create an instance of a Connection object # $conn = $Server->CreateObject("ADODB.Connection"); # Open it by providing a System DSN as the parameter # $conn->Open( "ADOSamples" ); # Deliberately cause an error by typo'ing the query # $conn->Execute( "ZELKECT * FROM Orders" ); if($conn->Errors->{Count} > 0) { $Response->Write("There's been an error ..."); $Response->Write($conn->Errors(0)); } $conn->Close(); # Close the connection undef($conn); # Destroy the object %>

<% $url = $Request->ServerVariables('PATH_INFO')->item; $_ = $Request->ServerVariables('PATH_TRANSLATED')->item; s/[\/\\](\w*\.asp\Z)//m; $params = 'filename='."$1".'&URL='."$url"; $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg; %> Return

view the source