I seem to be having a little trouble connecting to my subdomain's database. (It's a subdomain, I'm using space off of a friend's domain name) When I look at my database's port # it just says localhost (which should be correct because it's located on the same server).

I have a VB.net project, however, that cannot connect. (my friend has given me a few port #s that I might be able to use to connect, but they are not correct.) This is the code I'm using:

MySQLConnection = New MySqlConnection
        MySQLConnection.ConnectionString = "server=***.***.com;Port=***; User ID=*****; password=*****; database=*****;"

        Dim MyAdapter As New MySqlDataAdapter
        Dim SqlQuary = "SELECT VersionNumber From GameStats;"
        Dim Command As New MySqlCommand
        Command.Connection = MySQLConnection
        Command.CommandText = SqlQuary
        MyAdapter.SelectCommand = Command
        Dim Mydata As MySqlDataReader
        Mydata = Command.ExecuteReader
        If Mydata.HasRows = 0 Then
            MsgBox("Could not connect with database. Check firewall and/or try again at a later time.")
            While Mydata.Read()
                If Mydata(0).ToString = Label2.Text Then
                    LinkLabel1.Text = ""
                    Button1.Enabled = False
                    Button2.Enabled = False
                    LinkLabel1.Text = "Update to Version:" & Mydata(0).ToString
                End If
            End While
        End If

Can anyone point me in the right direction as how I can connect to a "localhost" on a server that isn't mine? I saw somewhere on some website (I could be totally wrong, I was up late that night and was running on 2 hours of sleep) that the website administrator had to change some configuration setting in his control panel (he is using cPanel) to allow me to access the database. Any help?

5 Years
Discussion Span
Last Post by maggoteer

To connect to the remote server, you would replace "localhost" with the remote machine's IP address or machine name.

I would also adapt the use of the SqlConnectionStringBuilder so you won't need to worry about spelling and punctuation (Like the space between USER and ID).


So just to clarify, I need to change the server= path to direct to the server's IP address, and what would the port number be? (More specifically, how would I find out)

As your suggestion about the SqlConnectionStringBuilder, I'm glad you actually mentioned that. When I first copied this code I idiotically put a space between the "=" sign and the actual reference name. Took me a couple of hours to figure out my mistake, but I finally found it. :) Hopefully it'll help other users when they are using similar code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.