Opening a Cursor on a Stored Procedure

In SQL Server 6.5, you can pass stored procedure parameters when you open a cursor by calling the SqlRpcInit function and the SqlRpcParam function.

The SqlRpcInit function has an options& parameter: SQLRPCCURSOR. Use SQLRPCCURSOR to specify the initialization of an input-parameter list for a subsequent cursor-open operation on a stored procedure. When you use SQLRPCCURSOR, you must set the rpcname$ parameter to an empty string.

No pending remote procedure calls (RPCs) can exist when you call SqlRpcInit with an options& of SQLRPCCURSOR. The SqlRpcInit function returns FAIL if pending RPCs have been initiated.

You can call the SqlRpcParam function to set the value for each stored procedure parameter that was used in the process of opening a cursor. Stored procedure parameters are no longer required to be constants, and they can be passed as follows.

    To open a cursor on a stored procedure that passes program variables as parameters
  1. Call the SqlRpcInit function once to initialize a new stored procedure. Set the rpcname$ parameter to an empty string, and set the options& parameter to SQLRPCCURSOR.
  2. Call the SqlRpcParam function once per parameter to set the value of each parameter of the stored procedure.
  3. Call the SqlCursorOpen function to open the cursor, and in the stmt$ parameter, specify only the stored procedure name.
  4. Call the remaining cursor functions as you would normally. For more information, see Microsoft SQL Server Programming DB-Library for Visual Basic, Chapter 5, "Cursor Functions."