有没有办法连接到没有ssl的mysql数据库?

7ajki6be  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(505)

我正在尝试连接到本地mysql数据库。
我有这个连接器:

using(MySqlConnection conn = new MySqlConnection("Database=Studentenverwaltung;Port=3306;Data Source=127.0.0.1;User Id=root;Password=abc123")) 
{
    try 
    {
        conn.Open();
        Console.WriteLine("Opened!");
        conn.Close();
    }
    catch(Exception e) 
    {
        Console.WriteLine("Cannot open Connection");
        Console.WriteLine(e.ToString());
    }
}

但我有个例外:
mysql.data.mysqlclient.mysqlexception(0x80004005):主机127.0.0.1不支持ssl连接。
它似乎无法连接到db,因为db不支持ssl。那么,有没有一种方法可以在没有ssl的情况下连接到db呢?

w8ntj3qf

w8ntj3qf1#

你试过设置 SslMode 属性设置为连接字符串中的“none”?
这应该起作用:

new MySqlConnection("Database=Studentenverwaltung;Port=3306;Data Source=127.0.0.1;User Id=root;Password=abc123;SslMode=none;")
lvmkulzt

lvmkulzt2#

using MySql.Data.MySqlClient;

private const String SERVER = "1.1.1.1";         // Server IP
private const String DATABASE = "abc";           // Date base name
private const String TABLE = "test";             // Table name
private const String UID = "user";               // Date base username
private const String PASSWORD = "pass";          // Date base password

public static void InitializeDataBase()
{                
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();

builder.Server = SERVER;
builder.UserID = UID;
builder.Password = PASSWORD;
builder.Database = DATABASE;
builder.SslMode = MySqlSslMode.None;
//builder.CertificateFile = @"<Path_To_The_File>\client.pfx";
//builder.CertificatePassword = "<Password_For_The_Cert>";

String connString = builder.ToString();
builder = null;

dbConn = new MySqlConnection(connString);         
}

相关问题