无法通过 Azure 函数连接到 Azure MySQL 数据库 - C#

Unable to connect to Azure MySQL Database through Azure Function - C#

我正在尝试从我正在创建的 Azure 函数连接到 Azure 的 MySQL 数据库(预览版)。但是,当我尝试打开连接时,我收到一条错误消息 Authentication failed because the remote party has closed the transport stream.

我的函数代码如下所示:

#r "System.Data"    <--- Uploaded System.Data.dll into the root folder
#r "MySql.Data"     <--- Uploaded MySql.Data.dll (6.9) into root folder

using MySql.Data; 
using MySql.Data.MySqlClient;
using System.Configuration;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    var connStr = ConfigurationManager.ConnectionStrings["MySQL_Conn"].ConnectionString;
    using(MySqlConnection conn = new MySqlConnection(connStr))
    {
        try{
            conn.Open();
            log.Info("Connection opened");
        }catch(Exception ex){
            log.Info("Error: " + ex.Message);
        }
    }
    //log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}

排查错误,这是我目前尝试过的方法:

None 这些方法对我有用。

如果有人能给我指明正确的方向,我会很高兴,因为那里的大多数指南都是针对 SQL 服务器的,而不是 MySQL 使用 C# 的。

谢谢

I get an error saying Authentication failed because the remote party has closed the transport stream.

我可以在我这边重现这个问题。似乎 MySql.Data 的版本导致了这个问题,如果我 upload project.json file 添加对 MySql.Data "7.0.7-m61" 的引用,我可以连接到 MySQL 数据库(预览)。

project.json

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "MySql.Data": "7.0.7-m61"
      }
    }
   }
}

函数代码和日志