-1

i'm new in vb .net programming, I've been encounter the following error when I'm trying to connect my form button to MySql database that: An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll Additional information: Keyword not supported. I have been working to troubleshoot this error but I didn't succeeded. Thanks for any help you are kind enough to provide! Please see my code for the class below:

Imports MySql.Data.MySqlClient Public Class Form1

Dim connect As New MySqlConnection

Dim connecto As String = "Server=localhost; User Id=root; Password; Database=sist"
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    connect.ConnectionString = connecto
    Try
        connect.Open()
        MessageBox.Show("Connected Successfully")
    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    End Try


End Sub

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label4.Text = Date.Now.ToString("MMM dd yyyy hh:mm:ss")
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Timer1.Enabled = True
End Sub

Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)

End Sub

End Class

carlodurso
  • 2,886
  • 4
  • 24
  • 37
kymb
  • 47
  • 3
  • 9
  • You don't do anything but connect and open the connection. Is that the right format for your connection string? (Side note - you should close the connection in a finally block) – Tim Oct 23 '14 at 20:11

1 Answers1

1
connect.ConnectionString = connecto

Your first line inside the Button1_Click sub references connect and connecto. But those objects are outside the scope of the sub. You could move the instantiation inside the sub and it would work.

So:

Dim connect As New MySqlConnection
Dim connecto As String = "Server=localhost; User Id=root; Password; Database=sist"
connect.ConnectionString = connecto
    Try
        connect.Open()
        MessageBox.Show("Connected Successfully")
    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    End Try

Or Better Yet

Dim connecto As String = "Server=localhost; User Id=root; Password; Database=sist"

Using connect As New MySqlConnection(connecto)
        Try
            connect.Open()
            MessageBox.Show("Connected Successfully")
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        End Try
End Using
Jason Hughes
  • 748
  • 6
  • 18
  • still this error persist, any help plz.....here is my codes Imports MySql.Data.MySqlClient Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim connect As New MySqlConnection Dim connecto As String = "Server=localhost; User Id=root; Password; Database=sist" connect.ConnectionString = connecto Try connect.Open() MessageBox.Show("Connected Successfully") Catch ex As MySqlException MessageBox.Show(ex.Message) End Try End Sub End Class – kymb Oct 24 '14 at 07:31
  • Can't read that... try editing your original question and using the code formatter. Also try giving Password a value. – Jason Hughes Oct 24 '14 at 19:39