1

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.

My Function code looks like this:

#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:

  • Copied the connection string and tried it with MySQL Workbench and it worked fine
  • Added the IP Address of my function's application to MySQL allowed IP List.

None of these method worked for me.

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#.

Thank you

3
  • You would be glad if you can be pointed to SQL Server? I don't get it. Please rewrite. Error itself: Add your connect string (without passwords). Check your mysql user if it is allowed to connect from the IP from your app too while you are at it. Commented Jun 19, 2017 at 0:45
  • My question is about Azure MySQL and Azure functions. I stated in the question that my connection string works fine. so I wanted someone to assist in solving this issue because I can't seem to find a guide related to Azure functions with MySQL. This is how my connection string looks like: Server={your_servername}; Port=3306; Database={your_database}; Uid={your_username}; Pwd={your_password}; SslMode=Preferred; Commented Jun 19, 2017 at 1:04
  • Given you have console app that you verify locally. Try run the same on kudu console (github.com/projectkudu/kudu/wiki/Kudu-console) to isolate rule out if Azure WebApps or Functions specific. Commented Jun 19, 2017 at 5:22

1 Answer 1

1

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

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

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

Function code and Logs

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.