Bonjour, j'ai réalisé un projet vb net consistant à faire des interaction avec une base de données.
J'ai voulu faire sous SQL (2008 R2 SP2) mais je suis basculer en MySQL.
Mon problème est le suivant :
Unable to connect to any of the specified MySQL Host
Mon programme veut pas se connecter a ma bdd MySQL :/
Voici mon code : (Form1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Imports Mysql.Data.Mysqlclient
Public Class Form1
Dim MySqlConn As MySqlConnection
Dim MySQLCommand As MySqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server=localhost;userid=database_2hcy;password=Quarks91;database=database_2hcy;"
Try
MySqlConn.Open()
MessageBox.Show("Connexion avec SQL réussite!")
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server=localhost;userid=database_2hcy;password=Quarks91;database=database_2hcy;"
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "select * from database.user_master where Username='" & TextBox1.Text & "' and Password='" & TextBox2.Text & "'"
MySQLCommand = New MySqlCommand(Query, MySqlConn)
Reader = MySQLCommand.ExecuteReader
Dim count As Integer
count = 0
While Reader.Read
count = count + 1
End While
If count = 1 Then
MessageBox.Show("Identifiants correctes!")
Form2.Show()
Me.Hide()
ElseIf count > 1 Then
MessageBox.Show("Identifiants dupliqués!")
Else
MessageBox.Show("Identifiants incorrectes!")
End If
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
End Class |
Screen de l'erreur : ![Nom : Erreur.png
Affichages : 782
Taille : 313,8 Ko](https://www.developpez.net/forums/attachments/p179833d1433581121/dotnet/acces-aux-donnees/ado-net/erreur-lors-connexion-serveur-mysql/erreur.png/)
Merci![:)](https://www.developpez.net/forums/images/smilies/icon_smile.gif)
Skype (au cas ou) : boolbich
Partager