0

I'm trying to connect to my mysql database (I'm hosted by infinityfree.net), entering these credentials:

connection = new MySqlConnection("Server=sql306.epizy.com; Port=3306; Database=epiz_27674946_db1; Uid=epiz_27674946; Pwd=**********; "); 

But I get this exception:

Unable to connect to any of the specified mysql hosts 

I don't know why this happens, the credentials should be right...

Can you help me?

Full code:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace sharetru { public partial class Form1 : Form { public Form1() { InitializeComponent(); } MySqlConnection connection; private void Form1_Load(object sender, EventArgs e) { try { connection = new MySqlConnection("Server=sql306.epizy.com; Port=3306; Database=epiz_27674946_db1; Uid=epiz_27674946; Pwd=*******; "); connection.Open(); if (connection.State == ConnectionState.Open) { label1.Text = "Connected"; label1.ForeColor = Color.Green; } else { label1.Text = "Not Connected"; label1.ForeColor = Color.Red; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } 
6
  • 3
    are you sure you can reach the server with those login credentials? have you verified it with a database tool? Commented Jan 28, 2021 at 11:13
  • if (connection.State == ConnectionState.Open) is a pointless if statement - the else is incredibly unlikely to be entered. Commented Jan 28, 2021 at 11:14
  • @Franz Gleichmann can you provide me a database tester or something? Commented Jan 28, 2021 at 11:25
  • are you sure, that your mysql is open for external access? it is possible, that there are restrictions for accessing the Database for security reasons Commented Jan 28, 2021 at 11:26
  • @PietroContadini no. but google can. there's myriads of database tools out there. Commented Jan 28, 2021 at 11:29

2 Answers 2

4

Regarding this service (infinityfree) it is not possible to access mysql from desktop applications (outside the infinityfree host)

https://support.infinityfree.net/mysql/how-to-connect-with-mysql/

Sign up to request clarification or add additional context in comments.

1 Comment

last paragraph is the important part: Finally, please note that it's NOT possible to connect to the free hosting databases from outside the hosting platform. This means you cannot access the database from desktop or mobile applications directly, or use them in applications hosted elsewhere.
-1

The code looks correct. The issue probably is in the connection string details.

Are you able to connect using the following connection details via some GUI tool? Workbench for example https://dev.mysql.com/downloads/workbench/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.