Using Stored Procedures If your application executes the same SQL statements multiple times, performance can be improved by creating a stored procedure on the server at prepare time. If your application executes one of these prepared statements multiple times, performance improves because the data provider created a stored procedure and executing a stored procedure is faster than executing a single SQL statement; however, if a prepared statement is only executed once or is never executed, performance can decrease. You can execute stored procedures in an application using the ADO.NET convention or by using ODBC escape sequences. Using the ADO.NET convention generally provides some performance benefits, because less overhead is required. The data provider is aware that it is processing a stored procedure, and does not have to parse the string to determine its contents. To enable stored procedures in an application using the approach built into ADO.NET: ■ Set the CommandText property in the Command object to the stored procedure name. The application does not need to specify the parameter markers. ■ Set the CommandType property in the Command object to StoredProcedure. ■ Specify the parameters in the Parameters collection, if needed. Alternatively, you can enable stored procedures using ODBC escapes: ■ Set the CommandText property in the Command object to the ODBC call escape. The following example uses an ODBC call to a stored procedure with three parameters: CommandText={call myproc(?,?,?)} ■ Set the CommandType property in the Command object to Text. ■ Specify the parameters in the Parameters collection, if needed. The order of the parameters that you add to the collection must match the order of the parameters defined in the stored procedure. See the "Using Stored Procedures" section in the data provider chapters for more information. To further enhance the performance benefits, you can enable statement caching. The data provider manages a cache of prepared statements to allow statements to be reused in subsequent application requests for similar statements. See “Using Statement Caching” for more information. NOTE FOR ADO.NET ENTITY FRAMEWORK USERS: The Connection object includes properties and methods that provide reauthentication and enhanced statistics functionality. The methods and properties are standard in the ADO.NET data provider, but are not available at the ADO.NET Entity Framework layer. Instead, you expose the same functionality through "pseudo" stored procedures. This approach uses the Entity Data Model (EDM) to achieve results that correspond to the ADO.NET results. This in effect provides entities and functions backed by pseudo stored procedures. For more information, see the chapter for your Entity Framework data provider.