ADO Stored Procedure Add-In

December 1999

Microsoft Corporation

Overview

This project is an example of building an Add-In for Visual Basic as a way of automating time consuming development tasks.  This Add-In automates the task of mapping stored procedure parameters to ADO Command object parameters and generating the associated code.

This folder contains the SprocAddIn Visual Basic 6.0 project and its associated DLL file.  It is an ActiveX DLL project which generates Active Data Objects (ADO) code for working with SQL Server stored procedures.

 

System requirements

Visual Basic

You will need Visual Basic 6.0 with Service Pack 3 to run the add-in or make changes to the source code.

Operating System

You add-in has been tested on Windows NT 4.0 SP3 (or newer) and Windows 2000.

Data Access Components

You must have ADO version 2.0 or newer installed on your computer in order to use the add-in.  The code that is generated by the add-in may work with prior versions of ADO, though this has not been tested.

Database

This add-in generates code for working with SQL Server databases.  It has been tested on SQL Server 7.0 but should also work without modification with SQL Server 6.5 databases.

 

Installation

In order to start working with this add-in, you need to register it.  There are two ways to accomplish this.  You can load the Visual Basic project and re-compile it (overwriting the supplied sprocaddin.dll file).  You can also open a command window and navigate to the folder containing the supplied sprocaddin.dll file and type the following:

regsvr32 sprocaddin.dll

This will enter the ActiveX DLL's information into the registry.  The next time you load Visual Basic you should see its menu option in the Add-Ins menu.

 

Working with the Add-In

The ADO Stored Procedure Code Wizard add-in allows you to insert Active Data Objects code into any code window.  Simply place the cursor in the function or subroutine where the code is to be inserted, and select the Add-Ins | ADO Stored Procedure Add-In... menu option.  The add-in form will be displayed.

At this point, you can select from the simple set of options presented, in order to choose the type of code to be generated.  When finished, click Insert to insert the code.  Note that the insert point (the procedure currently containing the cursor) is indicated above the insert button. 

If not already added, you will need to add a reference to the ADO object model before the code can be executed.

The code that is generated will work with ADO versions 2.0 or newer.   The add-in is not intended to generate completed code.  Its primary purpose is to automate the tedious process of mapping stored procedure parameters to ADO command parameters.  The add-in provides options to also generate variable declaration, as well as command preparation and execution.

 

Customizing the Add-In

The ADO Stored Procedure Code Wizard can be easily customized.  The Visual Basic project can be loaded and the code modified.  In particular, you may wish to customize the GenADOCode() function within the modSprocAddIn module, which creates the string containing the ADO code to be generated.

By re-compiling the project and overwriting the original sprocaddin.dll file, you will immediately be able to use the customized add-in. 

Note that you will not be able to re-compile the DLL if any instance of Visual Basic have the add-in loaded.  To unload, select the Add-Ins | Add-In Manager... menu option, select the ADO Stored Procedure Add-In entry, and uncheck the Loaded/Unloaded checkbox.

 

Known Issues

In order to generate the parameter definition code, the add-in calls the Refresh method of the ADO parameters collection to retrieve the stored procedure parameters from the database.  Stored procedure output parameters will be identified by ADO as adParamInputOutput, rather than adParamOutput.  The code that the add-in generates will still work, however, you may want to manually change the Params.Append method call to use the adParamOutput constant once the add-in has inserted the code into your project.

Also, if the stored procedure name contains a space, the call to Refresh will not retrieve the parameters unless the stored procedure name is enclosed in quotations within the CommandText property of the ADO command object.  The add-in automatically adds these quotes if it detects a stored procedure name containing a space.