【问题标题】:Unable to connect to Azure MySQL Database through Azure Function - C#无法通过 Azure 函数连接到 Azure MySQL 数据库 - C#
【发布时间】:2017-06-19 00:13:20
【问题描述】:

我正在尝试从我正在创建的 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}");
}

排除错误,这是我迄今为止尝试过的:

  • 复制了连接字符串,用 MySQL Workbench 试了一下,效果很好
  • 将我的函数应用程序的 IP 地址添加到 MySQL 允许的 IP 列表中。

这些方法都不适合我。

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

谢谢

【问题讨论】:

  • 如果您可以指向 SQL Server,您会很高兴吗?我不明白。请改写。错误本身:添加您的连接字符串(没有密码)。检查您的 mysql 用户是否也允许从您的应用程序的 IP 进行连接。
  • 我的问题是关于 Azure MySQL 和 Azure 函数。我在问题中说我的连接字符串工作正常。所以我希望有人协助解决这个问题,因为我似乎找不到与 MySQL 的 Azure 函数相关的指南。这是我的连接字符串的样子:Server={your_servername}; Port=3306; Database={your_database}; Uid={your_username}; Pwd={your_password}; SslMode=Preferred;
  • 假设您有在本地验证的控制台应用程序。尝试在 kudu 控制台 (github.com/projectkudu/kudu/wiki/Kudu-console) 上运行相同的操作,以隔离排除 Azure WebApps 或 Functions 特定的情况。

标签: c# mysql azure azure-functions


【解决方案1】:

我收到一条错误消息,提示 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"
      }
    }
   }
}

功能代码和日志

【讨论】:

    猜你喜欢
    • 2019-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多