Connection string syntax for Classic ADO / ODBC / Oracle 10g EZConnect

后端 未结 3 2008
别跟我提以往
别跟我提以往 2021-01-04 18:31

I\'m trying to connect various VBA projects to an Oracle 10g back end using ADO (2.8) and no TNS. After various attempts, we\'ve decided that the simplest series of steps fo

3条回答
  •  爱一瞬间的悲伤
    2021-01-04 19:22

    Similar to 'user1206604's answer - I set up an ODBC connection using ODBC Data Source Administrator (for example's sake we'll name it 'DEMO') and connect like this:

    Dim conn As New adodb.Connection
    Set conn = New adodb.Connection
    
    connStr = "Provider=OraOLEDB.Oracle;Data Source=DEMO;User Id=yourUserID;Password=yourPassword;"
    conn.Open connStr
    
    Dim api As New adodb.Recordset
    Set api = New adodb.Recordset
    
    yourQueryString = "SELECT foo FROM bar"
    api.Open yourQueryString, conn, adOpenDynamic, adLockReadOnly 
    'adjust above setting as needed
    
    while not api.EOF
      'do interesting stuff here
    wend
    
    'clean up resources
    api.Close
    Set api = Nothing
    
    conn.Close
    Set conn = Nothing
    

    The ODBC data source administrator is found (on my machine) in start menu > Programs > Oracle - oraClient10g > Configuration and Migration Tools > Microsoft ODBC Administrator and looks like this:

    ODBC Data Source Administrator

提交回复
热议问题