appyjack appyjack - 3 months ago 17
Vb.net Question

"The Microsoft.ACE.OLEDB.12.0 provider is not installed on your local machine" Exception is thrown while connecting to Access DataBase

I've been trying to connect a Microsoft database file to my visual basic application.

But when I try to connect it using code, it runs but as soon as I click the button to check the credentials it crashes (visual studio says it crashes in the bold area)

Code:


Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=P:\POS System\POS System Database.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Login Info WHERE Username = 'user" & txtStaffID.Text & "' AND password = 'user" & txtPassword.Text & "' ", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If (sdr.Read() = True) Then
'Pass verification and go to main form.
Me.Hide()
Else
MsgBox("Sorry, The Username or Password was incorrect.", MsgBoxStyle.Critical, "Information")
End If


but when i try to connect it through the wizard, i get this error. "The Microsoft.ACE.OLEDB.12.0 provider is not installed on your local machine"

Anyone have any ideas?

Answer

had that issue just yesterday. install 2007 Office System Driver and restart visual studio.

BTW, its a better practice to use ExecuteScalar() in order to to find a match between user and password in a login form:

  Dim result As Integer = 0
        Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data   source=P:\POS System\POS System Database.mdb")
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT COUNT(*) FROM Login Info WHERE    Username = 'user" & txtStaffID.Text & "' AND password = 'user" & txtPassword.Text & "' ", con)
        con.Open()
        result = DirectCast(cmd.ExecuteScalar(), Integer)
        con.Close()
        If result > 0 Then
            'Pass verification and go to main form.
            Me.Hide()
        Else
            MsgBox("Sorry, The Username or Password was incorrect.", MsgBoxStyle.Critical, "Information")
        End If