RDO: Getting Data from Temp Tables Created by Stored ProcedureLast reviewed: August 8, 1996Article ID: Q147938 |
The information in this article applies to:
SUMMARYIt is common to have stored procedures use temporary tables to build a result set. When using RDO (Remote Data Object) to call this type of stored procedure it appears as though RDO does not return any results, only an empty result set and no errors. Testing this same query with the Microsoft SQL Server version 6.0 ISQL utility produces the expected results, which leads you to believe RDO is restricted from reading these temporary tables. This is not an RDO restriction and RDO CAN retrieve data from a temporary table created in a stored procedure. However, no data access library can create a SCROLLABLE CURSOR on a temporary table created within a stored procedure. Temporary tables that are created within a stored procedure are DESTROYED when that stored procedure ends. If the table is not there, no data access library can possibly open a scrollable cursor on it, and go back to it when the next rowset is needed or when the user tries to update, insert or delete it. ISQL does not open a cursor, nor use a cursor library, so it just reads data off the pipe, one row at a time, read-only, forward-only (this is also the default mode of dblib so many people are used to working this way). The good news is that RDO can do this as well. You just need to tell SQL Server not to open a server-side cursor on the temporary table. This is done by setting the RowsetSize property to 1 and opening the result set as forward-only and read-only (just like ISQL does). RDO uses 100 as the default for RowsetSize, since this is the optimal setting for most cursor operations and when it is set to anything greater than 1, SQL Server' ODBC driver MUST attempt to create a server-side cursor, since fat rowsets require the ability to scroll and possibly update. Remember that using cursors is much different than the read-only, forward-only, rowset size of 1, approach to getting data back to the client. To support the operations that cursors do (like scrolling backwards, doing positioned updates, etc.), the source of the data has to live for the entire time the cursor is open. RDO can operate in a cursor mode, or a "fire hose" mode, which allows you to perform whatever functionality you want.
MORE INFORMATION
Sample ProgramStep 1: Create the Stored Procedure This stored procedure simply creates a temporary table called "#temptest," filling it with all the rows from the Authors table in the Pubs database.
Step 2: Create the Visual Basic CodeThe following Visual Basic code opens a connection to the server, creates a prepared statement for the stored procedure, sets the result set size to 1 and opens the result set as forward-only, read-only. When you run this code, all the author IDs and last names appear in the debug window. This sample code uses a "DSN-less" ODBC connection so you do not need to set up a DSN (Data Source Name) with the ODBC Admin utility.
REFERENCES
For complete documentation, refer to the "Microsoft ODBC 2.0 Programmer's Reference and SDK Guide." Hitchhiker's Guide to Visual Basic and SQL Server, Microsoft Press. ISBN: 1-55615-906-4.). |
Additional reference words: 4.00 vb4win vb432
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |