VB.Net 2010 / MySQL connection problem

cuemasterfl

Supreme [H]ardness
Joined
Jul 5, 2001
Messages
4,181
Any idea what's wrong with this? I have verified that the settings are correct with the database host. VS2010 gives me this error:

Cannot connect to database: Unable to connect to any of the specified mySQL hosts.

Thanks.

Code:
        SQL = "INSERT INTO `snaps` (`id` ,`username` ,`pictureid` ,`views` ,`date` ,`lastlook`) VALUES ('', '" & username & "', '" & imagefilename & imageextension & "', '0', '" & lastlook & "', " & "'" & lastlook & "'" & ")"

        MysqlConn = New MySqlConnection()
        MysqlConn.ConnectionString = "server=xxx.xxx.xxx.xxx;" & "user id=xxxxxx;" & "password=xxxxxx;" & "database=ezsnap_ezsnap"

        Try
            MysqlConn.Open()
            SQLCommand.Connection = MysqlConn
            SQLCommand.CommandText = SQL
            SQLAdapter.SelectCommand = SQLCommand
            Dim result As String = SQLCommand.ExecuteNonQuery

        Catch myerror As MySqlException
            MessageBox.Show("Cannot connect to database: " & myerror.Message)
        Finally
            MysqlConn.Close()
            MysqlConn.Dispose()
        End Try
 
Somewhat related question: What connection provider/product are you using to connect to MySQL? Or is it just an ODBC connection?
 
You should use bind parameters to avoid any chance of a SQL injection attack.
 
Back
Top