views:

284

answers:

2

In my code, why does nothing execute after con.Open(). If I step through each step, it ends the Form1_Load event after "con.Open()".

Imports System.Data.OleDb

Public Class Form1

Dim con As OleDbConnection
Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\testDB.accdb"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con = New OleDbConnection(strCon)
    con.Open()

    MsgBox("con open")
    con.Close()
    MsgBox("con closed")
End Sub

End Class

+3  A: 

Sounds like an Error is begin raised.

Have you tried framing your code with OnError Goto Handler type code? See the On Error Statement.

If this is VB.NET, trying catching an exception with Try ... Catch. Then set a breakpoint on the Catch statements to find out what the error is.

Frank Krueger
Put it in a try..catch. It throws some exceptions. The first is "System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on th local machine. ??
ScottK
Well, that is a problem. You will need to install that driver.
Frank Krueger
Thanks. I thought the Mircrosoft Object 12.0 Library reference was it.
ScottK
I installed the driver but still get the same exception. ?
ScottK
After installing the driver, I had to change the advanced compile configuration because I am running on Windows 7 64 bit. http://stackoverflow.com/questions/238625/vb-net-error-microsoft-ace-oledb-12-0-provider-is-not-registered-resolved
ScottK
@ScottK: you should post the compile options solution as an answer and accept it.
David-W-Fenton
I'm assuming he just locked the processor type to 32-bit.
Frank Krueger
A: 

After installing the MS Access Database Engine (to use Microsoft.ACE.OLEDB.12.0), my program still did not work. I still had the error:

"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local muoteachine."

I also had to change the advanced compile configuration because I am running on Windows 7 64 bit and may have "...locked the processor type to 32-bit".

How to change the settings:

1.Tools -> Options. 2.Check "Show all settings". 3.In the tree-view on the left hand side, select "Projects and Solutions". 4.In the options on the right, check the box that says, "Show advanced build configuraions." 5.Click OK. 6.Go to Build -> Configuration Manager... 7.In the Platform column select "new" in the drop down list. 8. Select "x86" under first dropdown box. 9. "Ok"

More info here: http://stackoverflow.com/questions/238625/vb-net-error-microsoft-ace-oledb-12-0-provider-is-not-registered-resolved

ScottK