Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: How do I connect
Bharath Devanathan wrote:
>
> Hi,
> I have just installed Oracle 7.3 and Visual Basic on my system. Could
> someone please tell the whole process as how to connect to the oracle
> database from VB. Please let me know the entire process from scratch
> including setting up the ODBC drivers.
>
> Thanks in advance,
>
> Regards,
>
> Bharath
> --
> Living on the earth can be expensive but it comes with a free annual
> trip around the sun!!!
Do you have a particular reason why you need to use ODBC? I'd suggest that since you are using VB that you use OLEDB via ADO for a DSN-less connection It will go much faster.
You would initialize ADO like this:
'******************************************************************** ' Subroutine: Ado_Init
'********************************************************************Public Sub Ado_Init()
On Error GoTo Errhand
Set Ora_Connection = New ADODB.Connection Set Ora_Command = New ADODB.Command Set Ora_Recordset = New ADODB.Recordset Set Ora_Recordset.Source = Ora_CommandExit Sub
Errhand:
Call MsgBox("Fatal Error while initializing ADO" & vbCrLf & vbCrLf & _ "Error Code: " & Err.Number & vbCrLf & _ "Error Source: Ado_Init" & " (" & _ Err.Source & ")" & vbCrLf & _ vbCritical, _ "Initialization")
and then call this function to connect:
'******************************************************************** ' Subroutine: Ora_Connect ' Connect to oracle. This is a DSN-less connection using the OLEDB' provider
'********************************************************************Public Function Ora_Connect(Optional ByVal ShowSuccess As Boolean = False) As Status
Dim strConnect As String
On Error GoTo Errhand
Ora_Connection.CursorLocation = adUseClient
strConnect = "Provider=" & Provider & ";" & _ "Data Source=" & frmOptions.txtServer & ";" & _ "User Id=" & frmOptions.txtPassword & ";" & _ "Password=" & frmOptions.txtPassword & ";"Ora_Connection.ConnectionString = strConnect Call Ora_Connection.Open
If ShowSuccess = True Then
Call MsgBox("Connected to Oracle", vbInformation, "Oracle Connection")
End If
Ora_Connect = Status_Success
Exit Function
Errhand:
Call MsgBox("Fatal error while connecting to Oracle" & vbCrLf & vbCrLf & _
"Error Code: " & Err.Number & vbCrLf & _ "Error Source: Ora_Connect" & " (" & _ Err.Source & ")" & vbCrLf & _ "Error Description: " & Err.Description, _ vbCritical, _ "Oracle")