【问题标题】:OLEDB Error in Visual Studio 2015 not in 2012Visual Studio 2015 中的 OLEDB 错误不在 2012 年
【发布时间】:2017-09-08 10:47:36
【问题描述】:

以下代码在我在 Visual Studio 2012 中运行时有效,但在 Visial Studio 2015 中无效:

 Dim strconn As String = "Provider=Microsoft.ACE.OLEDB.12.0;"

    strconn += "Data Source=" & FileNameAndPath & ";"

    If Has_Headers Then
        strconn += "Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;"""
    Else
        strconn += "Extended Properties=""Excel 12.0;HDR=NO;IMEX=1;"""
    End If

    Dim Conn As New OleDb.OleDbConnection(strconn)
    dt = New DataTable()

    ' create SQL to connect to correct table

    Dim mysql As String = "SELECT * FROM [" & SheetName & "$]"
    Dim adapter As New OleDb.OleDbDataAdapter(mysql, Conn)

    Try
        Conn.Open()
        adapter.Fill(dt)
        Conn.Close()
    Catch ex As Exception
        dt = New DataTable()
        MessageBox.Show("Error loading data from " & FileNameAndPath & ". Please check it is the correct format")
        Debug.WriteLine(ex.Message)
    Finally
        Conn.Dispose()
    End Try

尝试连接时发生错误。

错误是:

TestProgram.exe 中的 0x746FB802 (KernelBase.dll) 处引发异常:0xE0000002(参数:0x80004004)。

我在两者中都使用目标框架 .NET 框架 4.5.2 目标 CPU x86。

【问题讨论】:

  • 您使用的是 AnyCPU 配置还是 x64?如果是这样,请尝试使用 x86 查看是否是驱动程序版本问题。此外,异常消息应该还有更多内容。
  • 我在两者中都使用 x86。程序一碰到 conn.open 就崩溃了,它不会触发 try catch。我还收到一个错误“mincore\com\oleaut32\dispatch\ups.cpp(2128)\OLEAUT32.dll!75E45072: (caller: 75E4FE4F) ReturnHr(1) tid(3460) 8002801D Library not registered。”在上述异常之前出现。

标签: excel vb.net visual-studio-2012 visual-studio-2015 oledb


【解决方案1】:

我已经间接解决了这个问题。 我重新安装了 Microsoft Access Database Engine 2010,没有任何变化。 我只用上面的代码在 VS 2015 中创建了一个新的测试项目,它工作正常。 鉴于这似乎不是互联网上的常见问题,我认为它必须归结为文件损坏。 我删除了包含失败代码的模块并创建了一个新模块,复制并粘贴了相同的代码。这样就解决了问题。

【讨论】:

    猜你喜欢
    • 2017-06-14
    • 1970-01-01
    • 2018-04-27
    • 2023-04-04
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 2016-02-10
    相关资源
    最近更新 更多