I'm going to connect to mysql from c#.
However, when I try to connect to the internal ip address, conn returns NULL. The port is open and the connection string is not wrong. The root account has been given access from the outside and can also be accessed from the external OS. However, an error occurs when accessing from the c# program.
For your information, if you change the IP address to localhost, it will connect well.
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 DB_conn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ConnectionTest();
}
public static bool ConnectionTest()//db_conn
{
string connectString = string.Format("Server={0};Database={1};Uid ={2};Pwd={3};",
"192.168.0.24", "my_site", "root", "security");
try
{
using (MySqlConnection conn = new MySqlConnection(connectString))
{
conn.Open();
MessageBox.Show(string.Format("DB Access Complete."));
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
}
}