确定使用ms-access的ODBC故障(错误3146)的真正原因? [英] Determine real cause of ODBC failure (error 3146) with ms-access?
问题描述
我的客户端使用Access作为SQL Server数据库的前端.他们最近开始不时产生ODBC-运行某些报告时会出现3146错误.据我所知,这只是一个通用的ODBC调用失败错误.
My client is using Access as a front end to a SQL Server database. They recently started getting ODBC - 3146 errors from time to time when running some reports. From what I can tell, this is just a generic ODBC call failed error.
我尝试在启动报告的VB脚本中保留一些错误处理,但是我没有运气获得额外的错误信息.
I've tried sticking some error handling in the VB script that is launching the reports, but I am not having any luck getting extra error information.
代码看起来像这样.
Public Function RunReports()
On Error GoTo MyErrorTrap
DoCmd.OpenReport "blah", acViewPreview
DoCmd.Close
DoCmd.OpenReport "foo", acViewPreview
DoCmd.Close
Exit_function:
Exit Function
MyErrorTrap:
Dim errX As DAO.Error
Dim MyError As Error
If Errors.Count > 1 'This always seems to be 0, so no help
For Each errX In DAO.Errors 'These are empty even if dont check for Errors.Count
Debug.Print "ODBC Error"
Debug.Print errX.Number
Debug.Print errX.Description
Next errX
Else
Debug.Print "VBA Error"
Debug.Print Err.Number
Debug.Print Err.Description
End If
'Also have tried checking DBEngine.Errors, but this is empty too
End Function
我还启用了ODBC方面的跟踪功能,但是这使事情陷入了沉迷,到目前为止,我无法重新创建ODBC错误.
I've also enabled tracing on the ODBC side, but that has bogged things down way too much, and I am so far unable to recreate the ODBC error.
我完全愿意就如何诊断这一问题提出建议.
I am completely open for suggestions on how to diagnose this.
推荐答案
使用DbEngine.Errors
集合.
Sub Update_Temp()
On Error GoTo ErrorTrap
' Execute connect code at this point
Exit_errortrap:
Exit Sub
ErrorTrap:
Dim myerror As DAO.Error
For Each myerror In DBEngine.Errors
With myerror
If .Number <> 3146 Then
MsgBox .Description
End If
End With
Next
Resume Exit_errortrap
End Sub
要启用此代码,请确保在VBA设置中启用了错误处理.
To enable this code, make sure in VBA settings that error handling is turned on.
这篇关于确定使用ms-access的ODBC故障(错误3146)的真正原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!