Connection to Oracle


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Connection to Oracle

  1. #1
    serge Guest

    Connection to Oracle


    Hi
    This is my first time to connect to Oracle8 database
    and I can't .
    Im sure something wrong but I can't figure out.
    Any help would be appriciated.

    Configuration:
    I have one form with 3 textboxes.
    One okay button.

    I have a database in oracle8 with 3 columns
    id, fname and lname.
    user: user1
    pass: pass1

    file dsn(data source): Oracle Datasources

    Questions:
    1) How to set correctly the ODBC with ORACLE?
    2) Can you please correct thess codes?

    Thank you

    Dim cnn1 As ADODB.Connection
    Dim rstEmployees As ADODB.Recordset
    Dim strCnn As String
    Dim strID As String
    Dim strFirstName As String
    Dim strLastName As String
    Dim booRecordAdded As Boolean

    ' Open a connection.
    Set cnn1 = New ADODB.Connection


    'Oracle
    ''''''''''
    cnn1.Provider = "MSDAORA"
    cnn1.Open "Data Source=Oracle Datasources", "user1", "pass1"


    'Open Employee table.
    Set rstEmployees = New ADODB.Recordset
    rstEmployees.CursorType = adOpenKeyset 'check the diffences
    rstEmployees.LockType = adLockOptimistic
    rstEmployees.Open "employee", cnn1, , , adCmdTable

    ' Get data from the user.
    strID = Trim(InputBox("Enter employee ID:"))
    strFirstName = Trim(InputBox("Enter first name:"))
    strLastName = Trim(InputBox("Enter last name:"))

    ' Proceed only if the user actually entered something
    ' for both the first and last names.
    If (strID <> "") And (strFirstName <> "") _
    And (strLastName <> "") Then

    rstEmployees.AddNew
    rstEmployees!id = strID
    rstEmployees!fname = strFirstName
    rstEmployees!lname = strLastName
    rstEmployees.Update
    booRecordAdded = True

    ' Show the newly added data.
    MsgBox "New record: " & rstEmployees!id & " " & _
    rstEmployees!fname & " " & rstEmployees!lname

    Else
    MsgBox "Please enter an employee ID, " & _
    "first name, and last name."
    End If

    'Delete the new record because this is a demonstration.
    'cnn1.Execute "DELETE FROM employee WHERE emp_id = '" & strID & "'"

    rstEmployees.Close
    cnn1.Close

  2. #2
    Khawar Guest

    Re: Connection to Oracle


    Dear Friend

    First of all, you will have to create an alias using NetEasy Configuration
    utility in Oracle and then you will use this alias in host string setting
    in ODBC
    Check it out. I hope that It will work properly. I have to tell you that
    I have done it already by using the above procedure.




    "serge" <crgs@ica.net> wrote:
    >
    >Hi
    >This is my first time to connect to Oracle8 database
    >and I can't .
    >Im sure something wrong but I can't figure out.
    >Any help would be appriciated.
    >
    >Configuration:
    >I have one form with 3 textboxes.
    >One okay button.
    >
    >I have a database in oracle8 with 3 columns
    >id, fname and lname.
    >user: user1
    >pass: pass1
    >
    >file dsn(data source): Oracle Datasources
    >
    >Questions:
    >1) How to set correctly the ODBC with ORACLE?
    >2) Can you please correct thess codes?
    >
    >Thank you
    >
    > Dim cnn1 As ADODB.Connection
    > Dim rstEmployees As ADODB.Recordset
    > Dim strCnn As String
    > Dim strID As String
    > Dim strFirstName As String
    > Dim strLastName As String
    > Dim booRecordAdded As Boolean
    >
    > ' Open a connection.
    > Set cnn1 = New ADODB.Connection
    >
    >
    > 'Oracle
    > ''''''''''
    > cnn1.Provider = "MSDAORA"
    > cnn1.Open "Data Source=Oracle Datasources", "user1", "pass1"
    >
    >
    > 'Open Employee table.
    > Set rstEmployees = New ADODB.Recordset
    > rstEmployees.CursorType = adOpenKeyset 'check the diffences
    > rstEmployees.LockType = adLockOptimistic
    > rstEmployees.Open "employee", cnn1, , , adCmdTable
    >
    > ' Get data from the user.
    > strID = Trim(InputBox("Enter employee ID:"))
    > strFirstName = Trim(InputBox("Enter first name:"))
    > strLastName = Trim(InputBox("Enter last name:"))
    >
    > ' Proceed only if the user actually entered something
    > ' for both the first and last names.
    > If (strID <> "") And (strFirstName <> "") _
    > And (strLastName <> "") Then
    >
    > rstEmployees.AddNew
    > rstEmployees!id = strID
    > rstEmployees!fname = strFirstName
    > rstEmployees!lname = strLastName
    > rstEmployees.Update
    > booRecordAdded = True
    >
    > ' Show the newly added data.
    > MsgBox "New record: " & rstEmployees!id & " " & _
    > rstEmployees!fname & " " & rstEmployees!lname
    >
    > Else
    > MsgBox "Please enter an employee ID, " & _
    > "first name, and last name."
    > End If
    >
    > 'Delete the new record because this is a demonstration.
    > 'cnn1.Execute "DELETE FROM employee WHERE emp_id = '" & strID & "'"
    >
    > rstEmployees.Close
    > cnn1.Close



  3. #3
    Guztavo Benavides Hernández Guest

    Re: Connection to Oracle


    Hola Amigo

    Primero debes de instalar SQL Net para poder accesar a Oracle y el código
    para conectarse es el siguiente:

    Dim Cnn1 As ADODB.Connection
    Dim Rst1 As ADODB.Recordset

    Private Sub Form_Load()
    'Coneción a la Base de Datos Oracle
    Set Cnn1 = New ADODB.Connection
    Cnn1.Provider = "MSDAORA"
    Cnn1.ConnectionString = "Data source=ofiban; User ID=SYSTEM; Password=
    cmac"
    Cnn1.CursorLocation = adUseClient
    'Cnn1.ConnectionTimeout = 15
    'Cnn1.CommandTimeout = 30
    Cnn1.Open

    'Recordset de Cabecera de Leyes
    Set Rst1 = New ADODB.Recordset
    sql1 = "SELECT * FROM AHDMOVD"
    Rst1.Open sql1, Cnn1, adOpenDynamic, adLockOptimistic
    If Rst1.EOF And Rst1.BOF Then
    MsgBox "No Existen Datos de Tiempos de Operación Con Ese Rango de
    Fecha", vbInformation, "OBSERVACIONES"
    Else
    FillGrid1
    End If
    Screen.MousePointer = vbDefault
    End Sub

    Sub FillGrid1()
    Rst1.MoveFirst
    Do While Not Rst1.EOF
    var06 = Rst1!C_PRODUC
    CADENA = var06
    MSFlexGrid1.AddItem CADENA, 1
    Rst1.MoveNext
    Loop
    End Sub

    Sub ActuGrid1()
    With MSFlexGrid1
    .Clear
    .Rows = 1
    .Row = 0
    .Col = 0
    .Text = "CAMPO1"
    .ColWidth(0) = "1500"
    End With
    End Sub



    "Khawar" <sherlockhawar@hotmail.com> wrote:
    >
    >Dear Friend
    >
    >First of all, you will have to create an alias using NetEasy Configuration
    >utility in Oracle and then you will use this alias in host string setting
    >in ODBC
    >Check it out. I hope that It will work properly. I have to tell you that
    >I have done it already by using the above procedure.
    >
    >
    >
    >
    >"serge" <crgs@ica.net> wrote:
    >>
    >>Hi
    >>This is my first time to connect to Oracle8 database
    >>and I can't .
    >>Im sure something wrong but I can't figure out.
    >>Any help would be appriciated.
    >>
    >>Configuration:
    >>I have one form with 3 textboxes.
    >>One okay button.
    >>
    >>I have a database in oracle8 with 3 columns
    >>id, fname and lname.
    >>user: user1
    >>pass: pass1
    >>
    >>file dsn(data source): Oracle Datasources
    >>
    >>Questions:
    >>1) How to set correctly the ODBC with ORACLE?
    >>2) Can you please correct thess codes?
    >>
    >>Thank you
    >>
    >> Dim cnn1 As ADODB.Connection
    >> Dim rstEmployees As ADODB.Recordset
    >> Dim strCnn As String
    >> Dim strID As String
    >> Dim strFirstName As String
    >> Dim strLastName As String
    >> Dim booRecordAdded As Boolean
    >>
    >> ' Open a connection.
    >> Set cnn1 = New ADODB.Connection
    >>
    >>
    >> 'Oracle
    >> ''''''''''
    >> cnn1.Provider = "MSDAORA"
    >> cnn1.Open "Data Source=Oracle Datasources", "user1", "pass1"
    >>
    >>
    >> 'Open Employee table.
    >> Set rstEmployees = New ADODB.Recordset
    >> rstEmployees.CursorType = adOpenKeyset 'check the diffences
    >> rstEmployees.LockType = adLockOptimistic
    >> rstEmployees.Open "employee", cnn1, , , adCmdTable
    >>
    >> ' Get data from the user.
    >> strID = Trim(InputBox("Enter employee ID:"))
    >> strFirstName = Trim(InputBox("Enter first name:"))
    >> strLastName = Trim(InputBox("Enter last name:"))
    >>
    >> ' Proceed only if the user actually entered something
    >> ' for both the first and last names.
    >> If (strID <> "") And (strFirstName <> "") _
    >> And (strLastName <> "") Then
    >>
    >> rstEmployees.AddNew
    >> rstEmployees!id = strID
    >> rstEmployees!fname = strFirstName
    >> rstEmployees!lname = strLastName
    >> rstEmployees.Update
    >> booRecordAdded = True
    >>
    >> ' Show the newly added data.
    >> MsgBox "New record: " & rstEmployees!id & " " & _
    >> rstEmployees!fname & " " & rstEmployees!lname
    >>
    >> Else
    >> MsgBox "Please enter an employee ID, " & _
    >> "first name, and last name."
    >> End If
    >>
    >> 'Delete the new record because this is a demonstration.
    >> 'cnn1.Execute "DELETE FROM employee WHERE emp_id = '" & strID & "'"
    >>
    >> rstEmployees.Close
    >> cnn1.Close

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center