Consulting

Results 1 to 3 of 3

Thread: Connect to oracle from excel

  1. #1
    VBAX Regular
    Joined
    Jun 2012
    Posts
    29
    Location

    Connect to oracle from excel

    Hi all,
    I am very new to this field. I want to connect to oracle through VBA and retrieve data from table. I referred so many link but still not come to a final conclusion.
    I am really frustrated. Can anyone provide the code.
    I have select ADO object from tool-->Reference-->microsoft activex ADO 2.1 Object Library using odbc connection.

    <-------Information---->
    Data source name--jai
    Username-scott
    password----tiger
    server---oracl

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Lookup connection strings Oracle on Google to get started.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2009
    Posts
    40
    Location
    Hi Sarat,

    Here is code just copy and paste in new module

    [VBA]Sub connectDB()
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim strHost, strDatabase, pwd, strUser, strPassword As String
    Set conn = New ADODB.Connection


    strHost = "localhost"
    strDatabase = "ORCL"

    strUser = "HR"
    strPassword = "password"

    conn.ConnectionString = "Driver={Microsoft ODBC for Oracle}; " & _
    "CONNECTSTRING=(DESCRIPTION=" & _
    "(ADDRESS=(PROTOCOL=TCP)" & _
    "(HOST=" & strHost & ")(PORT=1521))" & _
    "(CONNECT_DATA=(SERVICE_NAME=" & strDatabase & "))); uid=" & strUser & " ;pwd=" & strPassword & ";"

    conn.CommandTimeout = 100000

    conn.Open

    Set rs = New ADODB.Recordset

    rs.Open "Employees", conn, adOpenKeyset, adLockBatchOptimistic

    ActiveCell.CopyFromRecordset rs

    conn.Close

    Set rs = Nothing
    Set conn = Nothing

    End Sub[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •