+ Reply to Thread
Results 1 to 3 of 3

Problem in executing query

  1. #1
    Registered User
    Join Date
    02-13-2006
    Posts
    46

    Problem in executing query

    Hi,
    I want to connect to a Oracle database located on remote machine and execute the insert query from the macro but i am getting error related to session object. I am sending the code, please help me out..

    CODE
    Dim oconn As ADODB.Connection
    Set oconn = New Connection
    Dim cmd As ADODB.Command
    Set cmd = New Command

    oconn.ConnectionString = "Driver={Oracle ODBC Driver};" & _
    "Dbq=alf;" & _
    "Uid=system;" & _
    "Pwd=manager1"

    cmd.ActiveConnection = oconn
    cmd.CommandText = "insert into zzz_ashish values('YYY','22')"
    cmd.Execute

  2. #2
    Tom Ogilvy
    Guest

    RE: Problem in executing query

    http://www.oracle.com/technology/doc...help/start.htm

    --
    Regards,
    Tom Ogilvy


    "ashishprem" wrote:

    >
    > Hi,
    > I want to connect to a Oracle database located on remote machine and
    > execute the insert query from the macro but i am getting error related
    > to session object. I am sending the code, please help me out..
    >
    > CODE
    > Dim oconn As ADODB.Connection
    > Set oconn = New Connection
    > Dim cmd As ADODB.Command
    > Set cmd = New Command
    >
    > oconn.ConnectionString = "Driver={Oracle ODBC Driver};" & _
    > "Dbq=alf;" & _
    > "Uid=system;" & _
    > "Pwd=manager1"
    >
    > cmd.ActiveConnection = oconn
    > cmd.CommandText = "insert into zzz_ashish values('YYY','22')"
    > cmd.Execute
    >
    >
    > --
    > ashishprem
    > ------------------------------------------------------------------------
    > ashishprem's Profile: http://www.excelforum.com/member.php...o&userid=31485
    > View this thread: http://www.excelforum.com/showthread...hreadid=545793
    >
    >


  3. #3
    Registered User
    Join Date
    02-13-2006
    Posts
    46

    Solution for connecting to Oracle

    Hi,
    I have found a code to connect to Oracle using macro. Dint understand much in the code but its working fine.
    Code :-

    Public objSession As Object
    Public objDataBase As Object
    Dim strSQL As String

    Sub final()
    ConnectToOracle Worksheets("sheet2")
    End Sub

    Sub ConnectToOracle(ws1 As Worksheet)
    'Create a reference to the OO4O dll
    Set objSession = CreateObject("OracleInProcServer.XOraSession")
    'Create a reference to my database

    Set objDataBase = objSession.OpenDatabase("AshishDB", "username/password", 0&)

    For i = 2 To ws1.UsedRange.Rows.Count
    strSQL = "insert into zzz_ashish values('" + ws1.Cells(i, 1) + "','" + CStr(ws1.Cells(i, 2)) + "')"
    objDataBase.ExecuteSQL (strSQL)
    Next i
    End Sub

    Regards,
    Ashish

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1