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

时间:2018-05-27 17:11:36

标签: c# mysql ado.net mysql-connector

我正在尝试连接到本地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连接。

似乎无法连接到数据库,因为数据库不支持SSL。那么有没有办法如何连接到没有SSL的数据库?

2 个答案:

答案 0 :(得分:9)

您是否尝试将[From, From Argument(s), To, To argument(s), And message also splitted] 属性添加到连接字符串?

这应该有效:

SslMode

答案 1 :(得分:1)

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);         
}