Jump to content

mysql server - connection problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
cinek

cinek

    Newbie

  • Members
  • PipPip
  • 13 posts
I'm trying to connect to mysql server with vb.net but I get an error: "Unable to connect to any of the specified hosts"

any ideas what I'm doing wrong?

this is the code I'm using:

1	Imports MySql.Data.MySqlClient 

2	 

3	Public Class connectForm 

4	 

5	    Dim conn As MySqlConnection 

6	 

7	 

8	 

9	    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

10	        SplashScreen1.ShowDialog() 

11	 

12	    End Sub 

13	 

14	    Private Sub cancelButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelButton1.Click 

15	        Me.Close() 

16	    End Sub 

17	 

18	    Private Sub connectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles connectButton.Click 

19	        conn = New MySqlConnection() 

20	        conn.ConnectionString = "server=" & serverTextBox.Text & ";" _ 

21	    & "user id=" & usernameTextBox.Text & ";" _ 

22	    & "password=" & passwordTextBox.Text & ";" _ 

23	    & "database=" 

24	 

25	        Try 

26	            conn.Open() 

27	            MessageBox.Show("Connection Opened Successfully") 

28	            conn.Close() 

29	        Catch myerror As MySqlException 

30	            MessageBox.Show("Error Connecting to Database: " & myerror.Message) 

31	        Finally 

32	            conn.Dispose() 

33	        End Try 

34	 

35	 

36	 

37	 

38	    End Sub 

39	End Class 

40	 


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It looks like you never specify the database.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
cinek

cinek

    Newbie

  • Members
  • PipPip
  • 13 posts
added a database - but I get the same error :(

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What is the resulting connection string?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
cinek

cinek

    Newbie

  • Members
  • PipPip
  • 13 posts
what do you mean? the server name?

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
no, what is conn.ConnectionString after you set it?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog