+ Reply to Thread
Results 1 to 5 of 5

Thread: How to connect to MySQL in VB.NET

  1. #1
    Junior Member Igrado is on a distinguished road
    Join Date
    Jan 2012
    Posts
    4

    How to connect to MySQL in VB.NET

    Hello all - I have subscribed to Host1Free in because I am a novice programmer and I want to learn how to use SQL in my programs. I am currently trying to learn how to connect to an SQL DB from my application and then upload and download data to the database. Below is my VB.NET code for opening a connection, but it is not working. I think that the problem is that I am trying to access the server incorrectly. I would appreciate any help you can give.

    Code:
    Imports MySql.Data.MySqlClient
    
    Public Class uwMainForm
    
        Dim sqlServer As String = "cimpletest.128pro.net"
        Dim sqlUsername As String = "cimple_stuser"
        Dim sqlPassword As String = "MYPASSWORD"
        Dim sqlConnection As MySqlConnection
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            sqlConnection = New MySqlConnection()
            sqlConnection.ConnectionString = "server=" & sqlServer & ";" &
                "user id=" & sqlUsername & ";" &
                "password = " & sqlPassword & ";" &
                "database=test"
            Try
                sqlConnection.Open()
                MessageBox.Show("Connection to Database has been opened.")
                sqlConnection.Close()
            Catch myerror As MySqlException
                MessageBox.Show("Cannot connect to database: " & myerror.Message)
            Finally
                sqlConnection.Dispose()
            End Try
    
        End Sub
    End Class
    
    I have also tried to connect using the direct ip address 71.215.225.9, but that doesn't work either.

    Thanks,
    Igrado

  2. #2
    Junior Member Igrado is on a distinguished road
    Join Date
    Jan 2012
    Posts
    4

    Re: How to connect to MySQL in VB.NET

    One mistake I found was that "database=test" should probably say "database = cimple_stutrans"

    With this change made, the error I am getting reads:
    Access denied for user 'cimple_stuser'@'ip72-***-*-***.dc.dc.cox.net'
    Last edited by Igrado; 01-30-2012 at 03:39 PM.

  3. #3
    Junior Member gamezone is on a distinguished road
    Join Date
    Dec 2011
    Posts
    18

    Re: How to connect to MySQL in VB.NET

    Dim sqlServer As String = "cimpletest.128pro.net"
    Is this you mysql server? ... and vb.net + sql is not very safe

  4. #4
    Junior Member Igrado is on a distinguished road
    Join Date
    Jan 2012
    Posts
    4

    Re: How to connect to MySQL in VB.NET

    That's the name of my host1free server, I don't know if that's the url I am supposed to use to access the mysql database that is included with the free package or not, but it's the only one I've been given.

    Why is .NET not safe?

  5. #5
    Super Moderator Modestas is on a distinguished road Modestas's Avatar
    Join Date
    Jun 2011
    Posts
    1,859

    Re: How to connect to MySQL in VB.NET

    If you are trying to connect to the databade which is in host1free, you need to use host1free server IP. In this case server IP is 94.249.139.6

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

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