vba Visual Basic 应用程序中的错误 440

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14455531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:17:02  来源:igfitidea点击:

Error 440 in Visual Basic Application

vbavb6ado

提问by no9

There is an old VB application running at one of my clients. An exception is throws in this peice of code:

我的一个客户端上运行着一个旧的 VB 应用程序。在这段代码中抛出了一个异常:

cn=GetIndexDatabaseConnectionString()
sSql="SELECT * FROM Arh_Naroc WHERE StNarocila = '" & isci & "'"                            
rs=CreateObject("ADODB.Recordset")
Call rs.Open(sSql,cn)

The exception happens in rs.Open()function. "Error number 440 occured."

异常发生在rs.Open()函数中。“出现错误号 440。”

This are SBL scripts for KOFAX engine and it's many years old. The whole SW was transferred from old XP computer to Windows 7 and looks like there are problems everywhere.

这是 KOFAX 引擎的 SBL 脚本,它已经有很多年的历史了。整个软件是从旧的XP电脑转移到Windows 7的,看起来到处都是问题。

Can some one help me determine what is the problem here. At least if I could get a proper error message back in msgbox would be most helpful.

有人可以帮我确定这里的问题是什么。至少,如果我能在 msgbox 中得到正确的错误消息,那将是最有帮助的。

EDIT: This is the connection string function.

编辑:这是连接字符串函数。

Function GetIndexDatabaseConnectionString
 Dim objXmlDocument As Object
 Dim objXmlGlobalSettingsFileParh As Object
 Dim objXmlIndexDatabaseConnectionString As Object
 Dim strGlobalSettingsFilePath As String
 Dim strTemp As String
 Const strSettingsFilePath = "C:\Data\LocalDocsDistibutingSystem\Settings.xml"
 Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
 objXmlDocument.Load strSettingsFilePath
 Set objXmlGlobalSettingsFileParh = objXmlDocument.selectSingleNode("DocsDistributingSystem/GlobalSettingsFilePath")
 strGlobalSettingsFilePath = objXmlGlobalSettingsFileParh.childNodes(0).Text
 Set objXmlGlobalSettingsFileParh = Nothing
 Set objXmlDocument = Nothing
 Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
 objXmlDocument.Load strGlobalSettingsFilePath
 Set objXmlIndexDatabaseConnectionString = objXmlDocument.selectSingleNode("DocsDistibutingSystem/AscentCapture/IndexDatabase/ConnectionString")
 strTemp = objXmlIndexDatabaseConnectionString.childNodes(0).Text
 Set objXmlIndexDatabaseConnectionString = Nothing
 Set objXmlDocument = Nothing
 GetIndexDatabaseConnectionString = strTemp
End Function

This is the relevant line from Settings.xml:

这是 Settings.xml 中的相关行:

<ConnectionString> Provider=OraOLEDB.Oracle;Data Source=LINO2;User Id=****;Password=****;OLEDB.NET=True; </ConnectionString>

The real data is masked with *. The connection to Oracle appears to be ok. I created ODBC and linked server to sql using the provider and connection data. It works. It must be something missing installed on the computer for ADODB to work...

真实数据用*屏蔽。与 Oracle 的连接似乎没问题。我使用提供程序和连接数据创建了 ODBC 和链接服务器到 sql。有用。必须是计算机上缺少安装的东西才能使 ADODB 正常工作...

The connection appears to be working OK. There is no error when its initialized. The error happens in Call rs.Open(sSql, cn). All i want is the detailed error message when the error happens... Many thanks.

连接似乎工作正常。初始化时没有错误。错误发生在 Call rs.Open(sSql, cn) 中。我想要的只是发生错误时的详细错误消息......非常感谢。

回答by Ryan McDonough

As it states on MS Knowledge Base

正如它在 MS 知识库上所说的那样

An error occurred while executing a method or getting or setting a property of an object variable. The error was reported by the application that created the object. Check the properties of the Err object to determine the source and nature of the error. Also try using the On Error Resume Next statement immediately before the accessing statement, and then check for errors immediately following the accessing statement.

执行方法或获取或设置对象变量的属性时发生错误。该错误是由创建对象的应用程序报告的。检查 Err 对象的属性以确定错误的来源和性质。还可以尝试在访问语句之前立即使用 On Error Resume Next 语句,然后在访问语句之后立即检查错误。

So as they suggest check the Err object, in a similar fashion to:

因此,他们建议以类似的方式检查 Err 对象:

If Err.Number <> 0 Then
  Msg = "Error: " & Str(Err.Number) & ", generated by " _
      & Err.Source & ControlChars.CrLf & Err.Description
  MsgBox(Msg, MsgBoxStyle.Information, "Error")
End If

So this will bring back the error in a MsgBox, however you can just use Response.Write if you want it easier to copy & paste etc..

因此,这将带回 MsgBox 中的错误,但是如果您希望更轻松地复制和粘贴等,您可以使用 Response.Write。

回答by Hrqls

to get the error description you can do as follows :

要获取错误描述,您可以执行以下操作:

Function GetIndexDatabaseConnectionString()
  On Error GoTo Errorfound
  'your
  'function
  'body
Exit Function
Errorfound:
  With Err
    MsgBox "Source: " & .Source & vbCrLf & "Desc: " & .Description, vbCritical, "Error " & CStr(.Number)
  End With 'Err
End Function