无法通过Azure功能连接到Azure MySQL数据库-C# [英] Unable to connect to Azure MySQL Database through Azure Function - C#

查看:189
本文介绍了无法通过Azure功能连接到Azure MySQL数据库-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to connect to Azure's MySQL Database (preview) from an Azure function I am creating. However, when I try opening the connection I get an error saying 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}");
}

解决错误,这是我到目前为止尝试过的:

Troubleshooting the error, this is what I have tried so far:

  • 复制连接字符串并在MySQL Workbench上尝试使用,效果很好
  • 将我的函数应用程序的IP地址添加到MySQL允许的IP列表中.

这些方法都不适合我.

None of these method worked for me.

如果有人能指出正确的方向,我会感到很高兴,因为那里的大多数指南都是针对SQL Server的,而不是针对具有C#的MySQL的.

I would be glad if someone can point me in the right direction since most of the guides out there is meant for SQL Server and not MySQL with C#.

谢谢

推荐答案

我收到错误消息Authentication failed because the remote party has closed the transport stream.

我可以重现此问题.如果我上传project.json文件,该文件添加了对MySql.Data "7.0.7-m61"的引用,我可以连接到MySQL数据库(预览版).

I could reproduce the issue on my side. It seems that the version of MySql.Data cause the issue, if I upload project.json file that adds a reference toMySql.Data "7.0.7-m61", I could connect to MySQL Database (preview).

project.json

project.json

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

功能代码和日志

Function code and Logs

这篇关于无法通过Azure功能连接到Azure MySQL数据库-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆