error closing mysql connection

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1576 Views - Last Post: 01 December 2011 - 03:40 PM Rate Topic: -----

#1 Neph1x   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 19-November 11

error closing mysql connection

Posted 19 November 2011 - 12:13 PM

I get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*' at line 1


Code:
        Dim cmd As New MySqlCommand(sqlquary, MySqlConnection)
        Dim login As MySqlDataReader
        Dim cmdd As New MySqlCommand
        Dim conn As String
        cmdd.Connection = MySqlConnection
        Myadapter.SelectCommand = cmdd
        login = cmd.ExecuteReader()
        Myadapter.SelectCommand = cmdd
        While login.Read
            TextBox1.AppendText(login.GetInt32(6))
            TextBox2.AppendText(login.GetInt32(8))
            login.Close()
        End While
        If username.Text = "" Or password.Text = "" Then
            PictureBox1.Show()
            PictureBox2.Show()
        Else
            If login.HasRows = 0 Then
                Label6.Show()
            Else
                If TextBox2.Text = 0 Then
                    Label6.Show()
                Else
                    If TextBox1.Text = 1 Then
                        Label7.Show()
                    Else
                        conn = "UPDATE Users SET Connected='" & Label2.Text & "' WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"
                        cmdd.CommandText = conn
                        cmdd.ExecuteNonQuery()
                        Form2.Show()
                        Me.Close()
                    End If
                End If
            End If
        End If



problem is there:

        While login.Read
            TextBox1.AppendText(login.GetInt32(6))
            TextBox2.AppendText(login.GetInt32(8))
            login.Close()
        End While


Please help me i don't know how to close "login.close()" connection before this:

conn = "UPDATE Users SET Connected='" & Label2.Text & "' WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"
                        cmdd.CommandText = conn
                        cmdd.ExecuteNonQuery()
                        Form2.Show()
                        Me.Close()



Thank you very much!

Is This A Good Question/Topic? 0
  • +

Replies To: error closing mysql connection

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,808
  • Joined: 12-June 08

Re: error closing mysql connection

Posted 19 November 2011 - 12:35 PM

Try just

cmdd.dispose()

Was This Post Helpful? 0
  • +
  • -

#3 Neph1x   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 19-November 11

Re: error closing mysql connection

Posted 20 November 2011 - 03:45 AM

View Postmodi123_1, on 19 November 2011 - 12:35 PM, said:

Try just

cmdd.dispose()

Thank you for that! but now i get new problem.

There is already an open DataReader associated with this Connection which must be closed first.

I have tried everything but still the same two problems
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,808
  • Joined: 12-June 08

Re: error closing mysql connection

Posted 20 November 2011 - 11:41 AM

... well dispose of the data reader first then!
Was This Post Helpful? 0
  • +
  • -

#5 Neph1x   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 19-November 11

Re: error closing mysql connection

Posted 20 November 2011 - 01:47 PM

View Postmodi123_1, on 20 November 2011 - 11:41 AM, said:

... well dispose of the data reader first then!

i tried this! when i do this then i get this error:

        Dim cmd As New MySqlCommand(sqlquary, MySqlConnection)
        Dim login As MySqlDataReader
        Dim cmdd As New MySqlCommand
        Dim conn As String
        cmdd.Connection = MySqlConnection
        Myadapter.SelectCommand = cmdd
        login = cmd.ExecuteReader()
        Myadapter.SelectCommand = cmdd
        While login.Read
            TextBox1.AppendText(login.GetInt32(6))
            TextBox2.AppendText(login.GetInt32(8))
            [color="#FF0000"]login.Dispose()[/color]
        End While
        If username.Text = "" Or password.Text = "" Then
            PictureBox1.Show()
            PictureBox2.Show()
        Else
            If login.HasRows = 0 Then
                Label6.Show()
            Else
                If TextBox2.Text = 0 Then
                    Label6.Show()
                Else
                    If TextBox1.Text = 1 Then
                        Label7.Show()
                    Else
                        conn = "UPDATE Users SET Connected='" & Label2.Text & "' WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"
                        cmdd.CommandText = conn
                        cmdd.ExecuteNonQuery()
                        Form2.Show()
                        Me.Close()
                    End If



You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*' at line 1

ughh :S
Was This Post Helpful? 0
  • +
  • -

#6 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: error closing mysql connection

Posted 20 November 2011 - 01:56 PM

You shouldn't be disposing it whilst you're in a loop with it!
Place the dispose code after the code for the loop!
Was This Post Helpful? 0
  • +
  • -

#7 Neph1x   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 19-November 11

Re: error closing mysql connection

Posted 20 November 2011 - 04:11 PM

i try it, and still same error :S
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,808
  • Joined: 12-June 08

Re: error closing mysql connection

Posted 20 November 2011 - 07:45 PM

What error?
Was This Post Helpful? 0
  • +
  • -

#9 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: error closing mysql connection

Posted 20 November 2011 - 10:26 PM

View PostNeph1x, on 21 November 2011 - 06:47 AM, said:

View Postmodi123_1, on 20 November 2011 - 11:41 AM, said:

... well dispose of the data reader first then!

i tried this! when i do this then i get this error:

        Dim cmd As New MySqlCommand(sqlquary, MySqlConnection)
        Dim login As MySqlDataReader
        Dim cmdd As New MySqlCommand
        Dim conn As String
        cmdd.Connection = MySqlConnection
        Myadapter.SelectCommand = cmdd
        login = cmd.ExecuteReader()
        Myadapter.SelectCommand = cmdd
        While login.Read
            TextBox1.AppendText(login.GetInt32(6))
            TextBox2.AppendText(login.GetInt32(8))
            [color="#FF0000"]login.Dispose()[/color]
        End While
        If username.Text = "" Or password.Text = "" Then
            PictureBox1.Show()
            PictureBox2.Show()
        Else
            If login.HasRows = 0 Then
                Label6.Show()
            Else
                If TextBox2.Text = 0 Then
                    Label6.Show()
                Else
                    If TextBox1.Text = 1 Then
                        Label7.Show()
                    Else
                        conn = "UPDATE Users SET Connected='" & Label2.Text & "' WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"
                        cmdd.CommandText = conn
                        cmdd.ExecuteNonQuery()
                        Form2.Show()
                        Me.Close()
                    End If



You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*' at line 1

ughh :S

The one that he posted, maybe?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,808
  • Joined: 12-June 08

Re: error closing mysql connection

Posted 20 November 2011 - 10:31 PM

Ah.. I wasn't aware that was an actual error.. I thought the OP was just posting more comments...
Was This Post Helpful? 0
  • +
  • -

#11 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1825
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: error closing mysql connection

Posted 20 November 2011 - 10:33 PM

The error is because you have a * at the end of your statement which should not be there:
 conn = "UPDATE Users SET Connected='" & Label2.Text & "' WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"

There should be no '*' after a semicolon.
Was This Post Helpful? 1
  • +
  • -

#12 Neph1x   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 19-November 11

Re: error closing mysql connection

Posted 21 November 2011 - 03:06 AM

View Postsmohd, on 20 November 2011 - 10:33 PM, said:

The error is because you have a * at the end of your statement which should not be there:
 conn = "UPDATE Users SET Connected='" & Label2.Text & "' WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"

There should be no '*' after a semicolon.


then how i can write this?
Dim sqlquary = "SELECT * From Users WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';*"

tnx!
Was This Post Helpful? 0
  • +
  • -

#13 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1825
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: error closing mysql connection

Posted 21 November 2011 - 03:15 AM

There is no that '*' at the end of the statement, it is simply:
	Dim sqlquary = "SELECT * From Users WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';"

Was This Post Helpful? 0
  • +
  • -

#14 Neph1x   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 19-November 11

Re: error closing mysql connection

Posted 21 November 2011 - 05:59 AM

View Postsmohd, on 21 November 2011 - 03:15 AM, said:

There is no that '*' at the end of the statement, it is simply:
	Dim sqlquary = "SELECT * From Users WHERE Username='" & username.Text & "'AND Password='" & password.Text & "';"

I tried, and without * i always get invalid username,password but both is correct!
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,808
  • Joined: 12-June 08

Re: error closing mysql connection

Posted 21 November 2011 - 07:29 AM

*sigh* I am not sure why you think causing a second error with the astricks is preferable to finding the root of your sql statement issue.

Are there extra spaces not being accounted for? Casing? Put a break point right after taht assignment for the sql string, pick it out of your code, and try it..
Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2