Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

mysql server - connection problem

mysql connection

  • Please log in to reply
5 replies to this topic

#1 cinek

cinek

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 29 January 2009 - 01:34 PM

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

  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 29 January 2009 - 01:46 PM

It looks like you never specify the database.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 cinek

cinek

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 29 January 2009 - 02:13 PM

added a database - but I get the same error :(
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 29 January 2009 - 05:35 PM

What is the resulting connection string?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 cinek

cinek

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 30 January 2009 - 02:14 AM

what do you mean? the server name?
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 30 January 2009 - 08:23 AM

no, what is conn.ConnectionString after you set it?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: mysql, connection

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download