Results 1 to 2 of 2

Thread: MS Excel & Oracle XE

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    1

    MS Excel & Oracle XE

    Hi,
    I am trying to connect to an Oracle XE database from excel. I have referenced the MS Active X Object Library 6. The code below executes up to the point of executing the sql statement. I get the error message:

    'The connection cannot be used to perform this operation. It is either closed or invalid in this context.'

    I would appreciate any help in solving this.


    Code:
        Dim conn, rs
        Dim strSQL As String
         
        Set conn = CreateObject("ADODB.Connection")
        With conn
            .ConnectionString = "Provider = MSDAORA;Data Source = 192.168.0.195:1521/XE;User ID = travel;Password = travel"
            .Open
        End With
         
        Set rs = CreateObject("ADODB.Recordset")
        strSQL = "select * From airlines"
        rs.Open strSQL
              
        rs.Close
        Set rs = Nothing
        conn.Close
        Set conn = Nothing

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: MS Excel & Oracle XE

    I have referenced the MS Active X Object Library 6.
    Welcome to the forums

    Try this... A slight change in your code. if it doesn't work, then we will take it from there...

    Code:
    Sub Sample()
        Dim conn As New ADODB.Connection, rs As New ADODB.Recordset
        Dim strConn As String, strSQL As String
        Dim myUser As String, myPassword As String
        
        myUser = "travel"
        myPassword = "travel"
        
        strConn = "Provider=MSDAORA;Data Source=192.168.0.195:1521/XE;" & _
        "Password=" & myPassword & ";User ID=" & myUser & ";Persist Security Info=True"
        
        conn.Open strConn
        
        strSQL = "select * From airlines"
        rs.Open strSQL
              
        rs.Close
        Set rs = Nothing
        conn.Close
        Set conn = Nothing
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

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



Click Here to Expand Forum to Full Width