Page 1 of 1

Connection error to mysql DB from pocket

Posted: Thu 14 May 2009 19:35
by lulu
Hi
I need help, i am developing a project, i try to insert values into a mysql database but when i execute the instruction i get an error


Dim cn As New MySqlConnection()
Dim myCommand As New MySql.Data.MySqlClient.MySqlCommand

cn.ConnectionString = "Server=0.0.0.0;Port=3306;Database=test;Uid=x;Pwd=x"
cn.Open()


Try
myCommand.CommandText = "INSERT INTO rechazos values ('Prueba Lulu 4')"
myCommand.ExecuteNonQuery()

Catch ed As Exception
MsgBox(ed.Message, MsgBoxStyle.Critical, "Error de conexion")
Finally
cn.Close()
End Try


And the error is

"Connection must be valid and open"

Is misssing me something ???

Thanks

Posted: Fri 15 May 2009 07:50
by Shalex
You didn't assign the cn object to the myCommand.Connection property.

Code: Select all

myCommand.CommandText = "INSERT INTO rechazos values ('Prueba Lulu 4')"
myCommand.Connection = cn
myCommand.ExecuteNonQuery()
If you use a provider that differs from Devart dotConnect for MySQL, please refer to the appropriate forum ( http://forums.mysql.com/list.php?38 ).