当我运行程序时,这没有用!
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服务器!
最佳答案
初始化连接时,不使用连接字符串属性strConnection
。尝试:
public void OpenConnection()
{
connection = new MySqlConnection(strConnection);
connection.Open();
}
关于c# - 连接到我的数据库时出错(MySQL,C#),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53502756/