I'm trying to connect mySQL database in my c# application but I'm stuck with a very short code that doesn't work.
I've tried a bunch of different code but all of them failed. I also tried to use a remote phpmyadmin database and a localhost database, none of them worked.
I'm connected to both of them and copy-pasted their logins in my code. I've disabled firewalls on my phpmyadmin server. I've open my 3306 port on my PC.
using System;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace Tests
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
string connetionString;
SqlConnection cnn;
connetionString = @"Data Source=localhost;Initial Catalog=my_projects;User ID=root;Password=123456";
cnn = new SqlConnection(connetionString);
cnn.Open();
MessageBox.Show("Connection Open !");
cnn.Close();
}
}
}
It should pop a message box with "Connection Open !" but it actualy loads for 30 seconds and gives me an error message: "The server can not be found or is not accessible".
Do you have any idea? My code is very short and all the searches I did where similar to the code I got there.