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 dbrpcinit function and the dbrpcparam function.

The dbrpcinit function has an option parameter: DBRPCCURSOR. Use DBRPCCURSOR to specify the initialization of an input-parameter list for a subsequent cursor-open operation on a stored procedure. When you use DBRPCCURSOR, you must set the rpcname parameter to NULL.

No pending remote procedure calls (RPCs) can exist when you call dbrpcinit with an option of DBRPCCURSOR. The dbrpcinit function returns FAIL if pending RPCs have been initiated.

You can call the dbrpcparam 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 dbrpcinit function once to initialize a new stored procedure. Set the rpcname parameter to NULL, and set the option parameter to DBRPCCURSOR.
  2. Call the dbrpcparam function once per parameter to set the value of each parameter of the stored procedure.
  3. Call the dbcursoropen 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 C, Chapter 5, "Cursor Functions."