0

i dont know how to fix this, i have already try everything.

Error System.InvalidOperationException' occurred in System.Data.dll

Additional information: The provider 'Microsoft.ACE.Oledb.12.0' is not registered on the local computer.

pops up on this code line commLogin.Connection.Open()

I need help!

    If TextBox1.Text = "" Then
        MessageBox.Show("Username!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error)
        TextBox1.Focus()
    ElseIf TextBox2.Text = "" Then
        MessageBox.Show("Password!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error)
        TextBox2.Focus()
    Else
        Dim conLogin As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.Oledb.12.0; Data Source = E:\projeto.mdb")
        Dim commLogin As New OleDb.OleDbCommand("SELECT login.password FROM login WHERE nome_util = @username AND password = @password", conLogin)
        Dim usernameParam As New OleDb.OleDbParameter("@username", Me.TextBox1.Text)
        Dim passwordParam As New OleDb.OleDbParameter("@password", Me.TextBox2.Text)

        commLogin.Parameters.Add(usernameParam)
        commLogin.Parameters.Add(passwordParam)
        commLogin.Connection.Open()

        Dim reader As OleDb.OleDbDataReader = commLogin.ExecuteReader()
        If reader.HasRows Then
            MessageBox.Show("ggwp", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
            principal.Show()
            Me.Hide()
        Else
            MessageBox.Show("Keep Trying", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error)
            TextBox1.Clear()
            TextBox2.Clear()
            TextBox1.Focus()
        End If
        commLogin.Connection.Close()
    End If

1 Answers1

2

InvalidOperationException is used in cases when the failure to invoke a method is caused by reasons other than invalid arguments. Typically, it is thrown when the state of an object cannot support the method call; in your case commLogin.Connection.Open().

The provider 'Microsoft.ACE.Oledb.12.0' is not registered on the local computer.

This error is because the Ace.Oledb.12.0 is not installed by default. You can install it here.

As a side note, look into Using Statements to dispose resources when you are done with them.

Sources: InvalidOperationException

Trevor
  • 7,777
  • 6
  • 31
  • 50
  • 1
    Or it's there but the Project/ACE have a different bitness. – Jimi Mar 27 '19 at 14:45
  • @Jimi correct, it could be different; I just assumed the reason being, most common, is it is not installed by default; the x64 version. – Trevor Mar 27 '19 at 14:46