![](/img/trans.png)
[英]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.