Best Way to Connect to Oracle Database from MS Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sedrick
    New Member
    • Aug 2011
    • 43

    Best Way to Connect to Oracle Database from MS Access

    I could not locate any other posts on this in the VBA forum. When I do a search it pulls in results from all forums.

    What is the best way to connect to an Oracle database with MS Access? It seems like I saw an alternative to ODBC some time ago that was better than ODBC.

    Thanks!
  • pod
    Contributor
    • Sep 2007
    • 298

    #2
    here is some vba code I use to connect to either three types of databases

    the "somefunctionca ll" function makes use of the "opendb" function to connect to a database...
    you will have to put in your parameters in the latter function and uncomment the "preferred connection string"

    Code:
    Public Function somefunctioncall() As String
        Dim objConn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim str As String
        str = ""
        Set objConn = opendb
        Set rs = objConn.Execute("SELECT * FROM sometable order by somefield ")
        Do While Not rs.EOF
        'some code here
            str = listAppend(str, rs(0) & ";" & rs(1), ";")
            rs.MoveNext
        Loop
        objConn.Close
        Set objConn = Nothing
        Set rs = Nothing
        sqlRWsrc = str
    End Function
    
    Public Function opendb() As ADODB.Connection
        Dim ORACLE_ConnString As String
        Dim SQL_ConnString As String
        Dim MSACCESS_ConnString As String
    '*****************************************************************
    '   this variable is used only when accessing a MS Access database
        Dim MSAdbPathAndName As String ' "C:\Reports\Database\msaccessdatabase.mdb"
    '*****************************************************************
    
        Dim DBN As String ' "DATABASENAME"
        Dim UID As String '"yourusername"
        Dim PWD As String '"yourPASSWORD"
        Dim DBS As String '"SERVERNAME"
        
        DBS = "thisismywebservername"
        UID = "thisisme"
        PWD = "thisismypassword"
        DBN = "thisismydbname"
        
        ORACLE_ConnString = "Provider=msdaora;Data Source=" & DBN & _
                            ";User Id=" & UID & ";Password=" & PWD & ";"
                            
        SQL_ConnString = "Provider=SQLOLEDB;DATA SOURCE=" & DBS & _
                            ";UID=" & UID & _
                            ";PWD=" & PWD & _
                            ";Initial Catalog=" & DBN & ";"
        
        MSACCESS_ConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
                                MSAdbPathAndName & ";"
        
        Set opendb = New ADODB.Connection
    '    *************** preferred connection string ***********
    '    uncomment the one you need
    '    *******************************************************
    
    
    '    opendb.Open ORACLE_ConnString
    
    '    opendb.Open SQL_ConnString
    
    '    opendb.Open MSACCESS_ConnString
        
    End Function

    Comment

    • Sedrick
      New Member
      • Aug 2011
      • 43

      #3
      Thanks!

      I am currently using DAO rather than ADO. Is there a way to do it with DAO too? If the user has Oracle client installed on the PC can a connection be made to the Oracle client? Which do you think would have the best performance?

      Comment

      • pod
        Contributor
        • Sep 2007
        • 298

        #4
        "Is there a way to do it with DAO too?"
        There might be a way. I was told once that it was better to use ADO, (maybe I was misinformed). And I have been using this way for the last 6 years without any problems.

        "If the user has Oracle client installed on the PC can a connection be made to the Oracle client?"
        You can connect to Oracle, use the Oracle connection string c/w the proper parameters, (DBS, DBN, UID and PWD) ... don't forget to uncomment the preferred string in the code

        "Which do you think would have the best performance?"
        I cannot answer that one, I can only tell you that I have good performance from the three connection strings I posted but then again my tools are for a few users (15 to 20 at most), not large scale


        You might have some fiddling to do with the code, but it should work... I got those string off the web by googling "connection strings" ...


        Bonne chance!

        p.s.
        by the way, Oracle "does not have to be installed" on the PC, I connect to the corporate Oracle database
        Last edited by pod; Sep 15 '11, 03:18 PM. Reason: clarification, typo

        Comment

        Working...