The information in this article applies to:
SUMMARYWith Visual Basic 5.0 and higher Enterprise edition, you have the ability to connect to an Oracle database through a DSN-Less connection, execute a stored procedure using parameters, and get return values from that stored procedure. The example in this article illustrates all of this functionality. MORE INFORMATION
The example in this article is a simple Visual Basic project that
creates a DSN-Less connection against an Oracle database and executes a
stored procedure. When working with Oracle and the Microsoft ODBC Driver
for Oracle, there are some settings that are different than working with
Microsoft SQL Server. These differences occur because you are using a
different ODBC driver.
NOTE: You must use Procedures that have output parameters and not Functions
when working with Oracle and RDO placeholder parameters.
The above scripts can be run from SQL*Plus or from within the Visual Database Tools Add-In in the Visual Basic 5.0 Enterprise edition. Once these objects have been created, you can create the Visual Basic project that will use them. Step-by-Step ExampleThis example project uses a simple form to send a bind parameter to the RDOINSERT stored procedure and then return the output parameter from that procedure. Here are the steps to create the project:
Following is a detailed explanation of the code used in this demonstration project: The Form_Load event contains the code that creates the DSN-Less connection. It also contains the code that creates the query that calls the stored procedure:
Note that you are not using the rdPreparedStatement object. This object has
been replaced by the rdoQuery object. This is new for RDO 2.0. Also, with
RDO 2.0, you do not need to explicitly create a connection object as is
done in this project. You can create a stand-alone query object that is not
specifically associated with a connection. To learn more about this
functionality, look up the rdoQuery Object in the Visual Basic 5.0
Enterprise edition Help file.
The connect string used to open a connection to an Oracle database (or any database) is very dependent upon the underlying ODBC driver. Even though similar parameters are used by most ODBC drivers (UID, PWD, etc.), the connect string used here will work only with the Microsoft ODBC Driver for Oracle:
The most important part of this connect string is the "CONNECTSTRING"
keyword. It is used only by the Microsoft ODBC Driver for Oracle. For
Microsoft SQL Server 6.5, you use the keyword "SERVER." The string assigned
to CONNECTSTRING is the Database Alias that you set up in SQL*Net. This is
the only difference in the connect string when connecting to an Oracle
database. All of the other parameters operate as described in the Help file
(under rdoConnection Object) for Visual Basic 5.0 Enterprise edition. As
stated in the Help file, for a connection, you do not specify a DSN in the
connect string.
Also in the Form_Load event is the code that creates the query object that calls the stored procedure:
With Oracle, you cannot specify a return value for a stored procedure call
as you can with Microsoft SQL Server 6.5; you must use stored procedures
that have output parameters as noted earlier in this article. The parameter
placeholders in the QSQL string are denoted by a "?" and referenced in the
order they in which they appear in the string. For more information on the
use of parameter placeholders in the rdoQuery object, refer to the
rdoParameter object in the Visual Basic 5.0 Enterprise edition Help file.
The remainder of the project is fairly straight-forward and well-documented in both the online Help file and Books Online, both of which come with Visual Basic 5.0. The RDO issues critical to working with Oracle, the connect string, and the calling of stored procedures have been detailed in this project. For more information on these issues, please consult your Oracle SQL*Net 2.3 documentation, the Help file for the Microsoft ODBC Driver for Oracle, and your Oracle 7 server documentation. © Microsoft Corporation 1999, All Rights Reserved. REFERENCES
Visual Basic 5.0 Enterprise Edition Help files
Additional query words: Oracle RDO Stored Procedure
Keywords : kbOracle kbVBp500 kbVBp600 kbDSupport |
Last Reviewed: August 23, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |