Generally speaking, we do this through ODBC to access the remote backend database. However, ODBC has a fatal drawback--slow speed. In fact, for Oracle databases, in addition to ODBC, we can use the OLE object (Oracle Objects for OLE) provided by Oracle itself to quickly access the database.
In Oracle V8, Oracle Objects for OLE (hereinafter referred to as OO) provides a set of simple, database-connected communication accesses for common development tools, supporting a variety of development environments that support VB custom controls or OLE Automation (OLE Automation). Oo is made up of three main parts:
L Oracle Object Server (Oracle)
• Oracle Data access control
L C + + class libraries (the Oracle Objects for OLE C + + class library)
Oo mainly includes objects and uses:
Oraclient defines the work domain and manages the session set.
Orasession manages the set of database objects and provides shared connectivity and transaction control.
Oraconnection the connection established between Oracle data.
Oradatabase a "virtual" login to the Oracle database.
Oraparamarray parameter group.
Oraparameter the relevant variables that are bound in an SQL statement or Pl/sql block.
Oradynaset the records obtained by using the SELECT statement.
Orasqlstmt a predefined, separate SQL statement.
Orafield the Columns (column) in the Oradynaset object.
Private Sub Command_click ()
Ls_server = "Baoprog"
' Join local Oracle Database
Ls_username = "System"
' User name is System
Ls_password = "Manager"
' Password is manager
' Create a Orasession object
Set orasession = CreateObject ("Oracleinprocserver.xorasession")
' Error handling
On Error GoTo Connect_err:
' Url:http://www.bianceng.cn/programming/vb/201410/45788.htm
' Create a Oradatabase object to join to the Oracle database
Set oradatabase = Orasession.dbopendatabase (ls_server, Ls_username + "/" + Ls_password, 0&)
On Error GoTo 0
Exit Sub
Connect_err:
If InStr (Orasession.lastservererrtext, "ORA-01017") Then
MsgBox "Invalid username and password, database join unsuccessful!", vbOKOnly + vbcritical, "prompt info"
Else
MsgBox the database join was unsuccessful! Please see the following error message: "+ Chr + orasession.lastservererrtext, vbOKOnly + vbcritical," prompt info "
End If
End Sub