Is there a way to connect to a MySQL database without ssl?

空扰寡人 提交于 2019-12-21 10:47:09

问题


I'm trying to connect to a local MySQL DB.

I have this connector:

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

But I get this Exception:

MySql.Data.MySqlClient.MySqlException (0x80004005): The host 127.0.0.1 does not support SSL connections.

It seems that it cannot connect to the DB because the DB doesn't support SSL. So is there a way how to connect to the DB whithout SSL?


回答1:


Have you tried to add the SslMode property to your connection string?

This should work:

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



回答2:


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


来源:https://stackoverflow.com/questions/50554578/is-there-a-way-to-connect-to-a-mysql-database-without-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!