Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to connect Excell 2017 to Oracle DB to get Data by using VBA code.

How to connect Excell 2017 to Oracle DB to get Data by using VBA code.

Scheduled Pinned Locked Moved Visual Basic
databaseoraclesysadminhosting
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hmanhha
    wrote on last edited by
    #1

    Hi All. I Want to use VBA code to get data from Oracle DB The code is here but I fail

    Const IPServer = "123.168.YY.XXX" ' Server hosting the Oracle db
    Const DBNAME = "NMS" '"DatabaseName"
    Const ORACLE_USER_NAME$ = "user"
    Const ORACLE_PASSWORD$ = "pass"
    Const port = "1521"
    Sub ConnectTOOracle()

    Dim oRs As ADODB.Recordset
    Dim oCon As ADODB.Connection
    Set oCon = New ADODB.Connection
    
    Dim mtxData As Variant
    Dim strConOracle As String
    
    strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) "
    strConOracle = strConOracle & "(HOST=" & IPServer & ")(PORT=port))(CONNECT\_DATA=(SERVICE\_NAME=" & DBNAME
    strConOracle = strConOracle & "))); uid=" & ORACLE\_USER\_NAME & " ;pwd=" & ORACLE\_PASSWORD & ";"
    
    
    
    
    oCon.Open strConOracle
    
    
    
    'Cleanup in the end
    Set oRs = Nothing
    Set oConOracle = Nothing
    

    End Sub

    Please help.

    L 1 Reply Last reply
    0
    • H hmanhha

      Hi All. I Want to use VBA code to get data from Oracle DB The code is here but I fail

      Const IPServer = "123.168.YY.XXX" ' Server hosting the Oracle db
      Const DBNAME = "NMS" '"DatabaseName"
      Const ORACLE_USER_NAME$ = "user"
      Const ORACLE_PASSWORD$ = "pass"
      Const port = "1521"
      Sub ConnectTOOracle()

      Dim oRs As ADODB.Recordset
      Dim oCon As ADODB.Connection
      Set oCon = New ADODB.Connection
      
      Dim mtxData As Variant
      Dim strConOracle As String
      
      strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) "
      strConOracle = strConOracle & "(HOST=" & IPServer & ")(PORT=port))(CONNECT\_DATA=(SERVICE\_NAME=" & DBNAME
      strConOracle = strConOracle & "))); uid=" & ORACLE\_USER\_NAME & " ;pwd=" & ORACLE\_PASSWORD & ";"
      
      
      
      
      oCon.Open strConOracle
      
      
      
      'Cleanup in the end
      Set oRs = Nothing
      Set oConOracle = Nothing
      

      End Sub

      Please help.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      hmanhha wrote:

      but I fail

      Yes, you fail to tell us what the problem is. However, looking at your code I get the feeling that ")(PORT=port))(CONNECT_DATA=(SERVICE_NAME=" is not correct. Probably should be: ")(PORT=" & port & "))(CONNECT_DATA=(SERVICE_NAME="

      H 1 Reply Last reply
      0
      • L Lost User

        hmanhha wrote:

        but I fail

        Yes, you fail to tell us what the problem is. However, looking at your code I get the feeling that ")(PORT=port))(CONNECT_DATA=(SERVICE_NAME=" is not correct. Probably should be: ")(PORT=" & port & "))(CONNECT_DATA=(SERVICE_NAME="

        H Offline
        H Offline
        hmanhha
        wrote on last edited by
        #3

        Thanks. I have modify it. But the problem the same. Run-Time error '-2147467259 (80004005': [Microsoft][ODBC Driver manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed. And warning Microsoft ODBC for Oracle. The Oracle (tm) client and networking componets were not found. These components are supplied by Oracle......

        M 1 Reply Last reply
        0
        • H hmanhha

          Thanks. I have modify it. But the problem the same. Run-Time error '-2147467259 (80004005': [Microsoft][ODBC Driver manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed. And warning Microsoft ODBC for Oracle. The Oracle (tm) client and networking componets were not found. These components are supplied by Oracle......

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Plug the warning into google and you will find there are some components you need to source from oracle, just like the warning says.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups