Remote Procedure Calls
The SQL Server driver uses the RPC facility in SQL Server to run procedures rather than pass procedures to SQL Server in an SQL statement. A procedure can be:
-
A prepared statement (which is a statement that is stored as a procedure)
-
A procedure that is called with the ODBC procedure syntax
-
A stored procedure that the SQL Server driver uses to implement a catalog function
RPCs have the following advantages over procedures passed in an SQL statement:
-
RPCs are faster than procedures passed in an SQL statement.
-
RPCs can have output parameters (however, see "Limitations," below); procedures passed in an SQL statement cannot. (A procedure can return a value in either case.)
To run a statement as an RPC, an application
-
Constructs an SQL statement.
-
Calls SQLBindParameter for each parameter in the statement.
-
Prepares the statement with SQLPrepare. (Note that the SQL_USE_PROCEDURE_FOR_PREPARE connection option must be set to SQL_UP_ON.)
-
Executes the statement with SQLExecute.
To run a procedure as an RPC, an application
-
Constructs an SQL statement that uses the ODBC procedure syntax. The statement uses parameter markers for each input, input/output, and output parameter, and for the procedure return value (if any).
-
Calls SQLBindParameter for each input, input/output, and output parameter, and for the procedure return value (if any).
-
Executes the statement with SQLExecDirect.
Note If an application submits a procedure using the SQL Server syntax (as opposed to the ODBC procedure syntax), the SQL Server driver passes the procedure call to SQL Server as an SQL statement rather than as an RPC.