执行vba脚本时出现未指定的运行时错误 [英] Unspecified run time error while executing vba script

查看:262
本文介绍了执行vba脚本时出现未指定的运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是vba的新手,我正在使用vba脚本从excel连接到数据库并获取记录.我为此编写了以下脚本.我遇到运行时错误'-2147467259(80004005)':未指定的错误. 如何解决此错误.查看错误屏幕截图.

I am new to vba and I am using vba script to connect to database from excel and get the records. I have written the following script for that.I am getting a run time error '-2147467259(80004005)':Unspecified error. How to resolve this error. See the error screen shot.

 Sub Ora_Connection()
        Dim con As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim query As String

        Set con = New ADODB.Connection
        Set rs = New ADODB.Recordset
        '---  Replace below highlighted names with the corresponding values
        strCon = "Driver={Microsoft ODBC for Oracle}; " & _
        "CONNECTSTRING=(DESCRIPTION=" & _
        "(ADDRESS=(PROTOCOL=TCP)" & _
        "(HOST=host_name)(PORT=1521))" & _
        "(CONNECT_DATA=(SERVICE_NAME=service_name))); uid=id; pwd=pw;"
        '---  Open the above connection string.
        con.Open (strCon)
        '---  Now connection is open and you can use queries to execute them.
        '---  It will be open till you close the connection
        query = "select * from security.forms"
        Set rs = con.Execute(query)

        For i = 0 To rs.Fields.Count - 1
            Sheet1.Cells(1, i + 1).Value = rs.Fields(i).Value
        Next



        con.Close
        End Sub

错误屏幕截图:

推荐答案

我遇到了完全相同的问题,很难找到答案,因为有关此问题的大多数帖子都没有答案.

I had the exact same problem and it was tough to find an answer since most posts on this issue are unanswered.

我通过使用另一个Oracle驱动程序解决了该问题.代替在Microsoft OraClient11g_home1 驱动程序中使用 Oracle的Microsoft ODBC for Oracle .希望对您有帮助

I solved it by using another Oracle driver. Instead of Microsoft ODBC for Oracle try using the Oracle in OraClient11g_home1 driver. Hope this helps

这篇关于执行vba脚本时出现未指定的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆