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

问题描述 投票:-1回答:1

[最近我在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

[最近我在Excel 2016上遇到问题。在excel 2016环境中关闭连接字符串后,系统仍然锁定excel,使其无法编辑(例如正在使用该文件)。但是代码正常工作...

excel vb.net excel-2016 oledbconnection aceoledb
1个回答
1
投票

检测到问题并解决

© www.soinside.com 2019 - 2024. All rights reserved.