【发布时间】: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