Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I wanted my windows form to be connected to the online database,
I mean I have a mysql database on phpmyadmin, on my hosting provider.
I am creating a windows form that must get data from this database.

i downloaded and installed the connector, and used a code to connect to the data base but i get a error that says "Unable to connect to any of the specified MySQL hosts.

What I have tried:

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class Form1
Dim con As New MySqlConnection
Dim cmd As New MySqlCommand


Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "server=localhost;port=3306; user id=myuserid; password=mypassword; database=mydatabasename"
con.Open() 'Error is in this line
cmd.Connection = con

Dim adp As New MySqlDataAdapter
Dim ds As New DataSet
cmd.CommandText = "Select fname from table_name where name='xyz'"
Me.TextBox1.Text = ToString(cmd.ExecuteScalar)
End Sub
End Class


I am sorry if I am not clear in any basis, but i need help
Posted
Updated 27-Feb-16 2:09am
v2

1 solution

localhost is for databases on the same machine only - most hosting services separate the database and web servers (or more usually have a database server farm) so you need to talk to them about exactly what the connection string should be. Only they can tell you, as it will need the SQL server name, together with your DB username and password - and these will be different for every hosting service.
Just to make life even more fun, you will need to check if the hosting service allows "remote connections" - some do, but many don't for security reasons. If they don't, then you can only access the DB from the website server code - not from a remote PC application.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900