[英]Can I ensure, using C#, that an X509Certificate was issued by a trusted authority?
[英]How can I connect to an RDS MySQL DB from C# using a Certificate Authority?
我正在构建需要连接到AWS RDS MySQL数据库的Xamarin.Mac
应用程序( C# )。
我有代码:
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("SELECT * FROM store", connection))
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1} {2}",
reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
}
}
}
我的连接字符串的格式为:
ConnectionString = "Server={0};Database={1}Uid={2};Pwd={3}";
但是,我似乎无法连接。 但是,通过MySqlWorkbench使用相同的主机和凭据,我可以很好地进行连接。 我看到我的RDS实例是在将证书颁发机构设置为rds-ca-2015
情况下构建的(没有选择不将其设置为此)。
如何使用上面的C#代码连接到该RDS DB?
原来,这并不具有认证机构做,因为我最初以为。
但是,我认为我会发布答案,因为我花了很长时间才找到解决方案,其他开发人员希望会发现它很有用。
因此,对于使用Xamarin.Mac来构建OSX应用程序的其他开发人员,您需要将您的项目设置为使用Xamarin.Mac .NET 4.5 Framework
。 启动新的OSX项目时,这不是默认设置,因此您必须更改它并重新定位软件包。 然后只需添加NuGet包MySql.Data
并将您的连接代码更新为:
using (MySqlConnection connection = new MySqlConnection(ConnectionString))
{
connection.Open();
using (MySqlCommand command = new MySqlCommand("SELECT * FROM store", connection))
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1} {2}",
reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
}
}
}
在那之后就像魅力一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.