Ace oledb 连接关闭文件仍在使用错误



最近我在Excel 2016上遇到了一个问题。关闭 excel 2016 环境中的连接字符串后,系统仍会锁定 excel 以进行编辑(例如正在使用该文件(。但是代码在 Excel 2007 和 2010 环境中运行良好(连接关闭后,该文件已准备好供我的下一个函数打开和编辑(。

在Excel 2016环境中,文件似乎需要锁定75秒,然后自动解锁,但这不会发生在Excel 2007和2010环境中

我应该在哪里更改它?

Public Function gf_ExcelConnection(ByRef strLocation As String, ByRef sWorksheetName As String, _
ByRef lExcelDataset As DataSet, ByRef iLastRow As Integer, _
ByRef sColumn As String) As Boolean
Dim strExcelConn As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & strLocation & _
"; Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1;"""
Dim ExcelConn As New System.Data.OleDb.OleDbConnection(strExcelConn)
Dim ExcelCommand As OleDbCommand = New OleDbCommand
Dim ExcelDataAdapter As New OleDbDataAdapter
Try
gf_ExcelConnection = True
ExcelCommand.CommandText = "SELECT * FROM [" + sWorksheetName + "A1:" & sColumn & iLastRow & "] "
ExcelDataAdapter.SelectCommand = ExcelCommand
ExcelDataAdapter.SelectCommand.Connection = ExcelConn
MsgBox(103)
ExcelConn.Open()
ExcelDataAdapter.Fill(lExcelDataset, "ImportTable")
ExcelConn.Close()
ExcelConn.Dispose()
MsgBox(104)
Catch ex As Exception
gf_ExcelConnection = False
gclsError.gf_ErrorHandler("InvalidIncorrectFile", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error, False)
ExcelConn.Close()
Finally
ExcelConn.Close()
ExcelConn.Dispose()
ExcelConn = Nothing
MsgBox(105)
End Try
End Function

检测到并解决问题

此问题是由于最近Microsoft更新的MS Office产品。

卸载并重新安装 AccessDatabaseEngine (Microsoft Access Database Engine 2016 Redistributable( 后。 万岁..错误没有出现

相关内容

  • 没有找到相关文章

最新更新