ADO recordset crashes while evaluating EOF after Excel upgrade

风格不统一 提交于 2021-01-29 16:22:16

问题


I have an Excel sheet that connects to a Basis database using an ODBC connection. It worked fine when we were running Excel 2010 on Windows Server 2008, but then we upgraded to Excel 2016 on Windows Server 2016, and it doesn't work anymore.

Here's some code that demonstrates the problem:

Public Sub cnntest()
Dim cnn As ADODB.Connection
Dim sql As String
Dim rs As ADODB.Recordset

Set cnn = New ADODB.Connection
cnn.Open "DSN=redacted;UID=redacted;PWD=redacted;"

sql = "SELECT ITEM FROM IC_ITM_MST WHERE ITEM = '1400-4'"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open sql, cnn

For Each a In rs.Fields
    Debug.Print a.Name
Next a

Debug.Print rs.EOF

rs.Close
cnn.Close
End Sub

When I run the above code, it prints the name of the field, so I know that it's connecting to the database and executing the query. However, when it tries to evaluate rs.EOF, it immediately crashes and throws up an error message saying "Microsoft Excel has stopped working." It also does this when I mouse over that part of the code. The exact same code runs fine when I try it on Excel 2010 on Windows Server 2008.

Any idea why it works on the old version of Excel but not the new one? Any ideas on how to fix it?


回答1:


Four months later, I finally found the answer. I used the Windows event viewer to look at the error logs for the crashes, which said

"Faulting application name: EXCEL.EXE, version 16.0.4266.1001, time stamp: 0x55ba1551 Faulting module name: BBjODBC.dll, version 14.1.1.0, time stamp: 0x5400df87 Exception code: 0xc0000005

This confirmed that the problem was with the BBj driver. It turns out that the person responsible for updating that driver had updated it on all of the server's hard drives except for the C drive, which was the one that Excel decided to use. As a result, we were stuck using a five year old version of the driver even though our tech people claimed everything was up to date. We're currently waiting for the driver to be updated, so hopefully that will fix the issue.



来源:https://stackoverflow.com/questions/54337981/ado-recordset-crashes-while-evaluating-eof-after-excel-upgrade

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!