<%@ LANGUAGE = PerlScript%> ADO Stored Procedures
ActiveState PerlScript

ActiveX Data Objects (ADO) Stored Procedures

Calling stored procedures can be done with the Command object. Store the name of the procedure in a scalar variable, set the ActiveConnection-property to either a Connection object or a valid ConnectionString and then specify the stored procedure to run and specify that the Commandis a stored procedure. The stored procedure used is named "get_customer" and looks as follows:
CREATE PROCEDURE get_customer @cust_id nchar(5)
SELECT * FROM Customers WHERE CustomerID=@cust_id
It is written for the Northwind database, and to work with the parameters, from ADO you call Refresh() to get the Parameters that the stored procedure call takes, then set a valid value, and execute the procedure. The example was written for the Northwind database on SQL Server 7.0 and 2000, but can easily be modified to work with other databases.

Output from stored procedure:
<% # Import the constants # use Win32::OLE::Const 'Microsoft ActiveX Data Objects 2.5'; # Set the name of the stored procedure to run # $stored_procedure = "get_customer"; # Create the Command object # $cmd = $Server->CreateObject('ADODB.Command'); # Set the string used to connect to the database # $cmd->{ActiveConnection} = (<{CommandText} = $stored_procedure; # The type of the command -- will not work without it # $cmd->{CommandType} = adCmdStoredProc; # Very important # Refresh the parameters collection so that you have all parameters available # $cmd->Parameters->Refresh(); # Set the value of the parameter to use # $cmd->Parameters('@cust_id')->{Value}='ALFKI'; # Execute the Command # $rst = $cmd->Execute(); # Get the number of fields # $count = $rst->Fields->{Count}; # Loop the fields # for(my $i=0; $i<$count; $i++) { $Response->Write($rst->Fields($i)->{Name}); $Response->Write(": "); $Response->Write($rst->Fields($i)->{Value}); $Response->Write("
"); } undef($cmd); %> <% $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; %>


view the source