当我运行程序时,这不起作用!
using MySql.Data;
using MySql.Data.MySqlClient;
namespace MySQL
{
class SqlConnection
{
public SqlConnection() { }
~SqlConnection() { }
private string strConnection = "Server=localhost;Database=database;Port=3306;User ID=root;Password=";
private MySqlConnection connection;
public void OpenConnection()
{
connection = new MySqlConnection();
connection.Open();
}
public void CloseConnection()
{
connection.Close();
connection.Dispose();
}
public string StrConnection
{
set
{
StrConnection = value;
}
get
{
return StrConnection;
}
}
}
}
但是它不起作用!
错误:不允许主机“ xxx”连接到此MariaDB服务器!
答案 0 :(得分:3)
初始化连接时,不使用连接字符串属性strConnection
。试试:
public void OpenConnection()
{
connection = new MySqlConnection(strConnection);
connection.Open();
}