OLEDB Error in Visual Studio 2015 not in 2012

0

The following code works when I run it in Visual Studio 2012, but not in 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

The error occurs when it attempts the connection.

The error is:

Exception thrown at 0x746FB802 (KernelBase.dll) in TestProgram.exe: 0xE0000002 (parameters: 0x80004004).

I'm using target framework .NET framework 4.5.2 in both target CPU x86.

excel
vb.net
visual-studio-2012
visual-studio-2015
oledb
asked on Stack Overflow Sep 8, 2017 by DovesandChicks • edited Sep 8, 2017 by David Pilkington

1 Answer

0

I've resolved this indirectly. I reinstalled the Microsoft Access Database Engine 2010, no change. I created a new test project in VS 2015 with only the code above, it worked. Given that this didn't appear to be a common problem across the internet I decided it must be down to a corrupted file. I deleted the module containing the failing code and created a new one, with the same code copied and pasted in. That solved the problem.

answered on Stack Overflow Sep 15, 2017 by DovesandChicks

User contributions licensed under CC BY-SA 3.0