This article introduces the methods and steps for accessing remote databases in VB.
Remote Data Objects (RDO) is an object model based on the ODBC API in VB 5.0. It is short, fast, and robust. It can access any 32-bit ODBC data source, such as SQL Server and Oracle database. It is a newer and more advanced tool for accessing remote databases. .
The general method of using RDO is as follows.
(1) Declare the variables first: Public con As rdoConnection, res As rdoResultset
(2) Then initialize rdoEngine and set default parameters such as user and password;
With rdoEngine
.rdoDefaultUser = sa 'User is sa
.rdoDefaultPassword = pass 'The password is pass
.rdoDefaultCursorDriver = rdUseServer
.rdoDefaultLoginTimeout = 15
End With
(3) Then connect to the remote database to be accessed (DSN Connection and DSN-Less Connection can be used).
Example using DSNC connection (connecting to the database hotel on the server SERVER):
Set con = rdoEnvironments(0)
.OpenConnection (hotel, rdDriverNoPrompt, False)
Example of using DSN-Less Connection (connecting to the database hotel on the server SERVER):
Set con = rdoEnvironments(0)
.OpenConnection (, rdDriverNoPrompt, False, driver={SQL Server}; server= _ SERVER; database=hotel)
After the connection is established, you can use the OpenResultset method to execute queries and process the result set, and you can use the Execute method to perform action queries including data definition and data operations. For example:
Set res = con.OpenResultset (SELECT * FROM menu, rdOpenStatic)
con.Execute CREATE VIEW menu_view AS SELECT code, dish name FROM menu, rdExecDirect
One of the most powerful and important features of RDO is that it can query and process results returned by stored procedures, no matter how complex it is.
In addition to RDO, RDC can also be used to access remote databases.
Remote Data Control (RDC) is similar to Data Control (DC), except that RDC uses RDO to connect to the ODBC driver manager, while DC uses DAO to connect to the Jet database engine. Using RDO and RDC, you can access ODBC data sources without using the Jet engine. This allows for better performance and greater flexibility when accessing remote databases.
Examples of using remote data control MSRDC are as follows.
Connect: driver={SQL Server}; server=SERVER; database=hotel
DataSourceName:
SQL: SELECT * FROM menu
UserName: sa
Password: pass
CursorDriver: 3-rdUseClient
You can use RDC to perform many simple remote data access operations without writing any code. You only need to fill in the relevant items, which is very convenient to use. But it should be noted that unless disabled at design time and only started when needed, RDC will consume at least one remote database connection. In situations where remote database connection resources are limited or require high efficiency, RDC should be used with caution and sparingly. In this case, you should consider using RDO whenever possible and use stored procedures (precompiled SQL statements).
Finally, it should be noted that only 32-bit operating systems (such as Windows NT or Windows 95) can support RDO and RDC. RDO and RDC can also only be used to access 32-bit ODBC data sources.