Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: How do I connect

Re: How do I connect

From: K Stahl <BlueSax_at_Unforgettable.com>
Date: 2000/02/16
Message-ID: <38AAF1B0.BCBC56FE@Unforgettable.com>#1/1

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

' Initialize variables used in the program
'********************************************************************
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_Command
    Exit 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")

End Sub

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
    Set Ora_Command.ActiveConnection = Ora_Connection     Ora_Command.CommandType = adCmdText     

    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")

    Ora_Connect = Status_Fatal
End Function Received on Wed Feb 16 2000 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US