且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查 MySqlConnection 是否使用 SSL

更新时间:2023-11-28 15:48:58

您可以查看SSL"一词的连接字符串.这将让您知道在这种情况下您的 IDbConnection 是否使用 ssl.有关可用于 MySql 的连接字符串列表,请访问 ConnectionStrings.com.如果这能解决您的问题,请告诉我.

You can look at the connection string for the word "SSL". This would allow you to know if your IDbConnection is using ssl in this case. For a list of the connection strings that you could use with MySql, please visit ConnectionStrings.com. Let me know if this solves your problem.

我会尝试查看连接字符串.这是一个证明这一点的解决方案.

I would try looking at the connection string. Here is a solution to demonstrate this.

var connStr = "Data Source=example.com;Port=3306;Database=Foo;User Id=root;Password=foo;SSL Mode=Required";
var sslElement = connStr.Split(';')
    .SingleOrDefault(s => s.StartsWith("SSL", StringComparison.InvariantCultureIgnoreCase));

var sslModeEnabled = (sslElement != null 
    && string.Equals(sslElement.Split('=')[1].Trim(), "None", StringComparison.InvariantCultureIgnoreCase) == false);


Console.WriteLine($"SSL Mode Enabled: {sslModeEnabled}");