我无法连接到MySQL数据库,我正在使用xampp。 它从简单的代码错误中指出了此错误:“与服务器的连接失败!”
namespace Mysql
{
public partial class Form1 : Form
{
private MySqlConnection conn;
private string server;
private string database;
private string uid;
private string password;
public Form1()
{
server = "localhost";
database = "tut1";
uid = "root";
password = "";
string connString;
connString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};";
conn = new MySqlConnection(connString);
InitializeComponent();
}
答案 0 :(得分:1)
好的,所以我知道了。我修复了SslMode = none的问题。
答案 1 :(得分:0)
您的连接字符串应如下所示
Server = myServerAddress; Database = myDataBase; Uid = myUsername; Pwd = myPassword;
下面是结构
服务器= {0};用户ID = {1};密码= {2};数据库= {3};
您需要将密码指定为Pwd