简体   繁体   English

无法连接到任何指定的 MySQL 主机? C# + Heroku + ClearDB

[英]Unable to connect to any of the specified MySQL Hosts? C# + Heroku + ClearDB

I have a web API hosted on Heroku.我在 Heroku 上托管了一个 Web API。 It serves data from a ClearDB via a Golang program.它通过 Golang 程序提供来自 ClearDB 的数据。 I have a C# .NET script that will need to insert data into that ClearDB.我有一个 C# .NET 脚本,需要将数据插入到该 ClearDB 中。 I had this idea working on my local machine, but as I moved everything over to heroku, the C# part stopped working.我有这个想法在我的本地机器上工作,但是当我把所有东西都转移到 heroku 时,C# 部分停止工作。

I have been successful in connecting with MySQL Workbench 8.0 and with my Golang program itself.我已经成功地连接到 MySQL Workbench 8.0 和我的 Golang 程序本身。 The GO program can successfully connect, query, and serve data. GO 程序可以成功连接、查询和服务数据。

I know there are many other questions like this, and most of them seem to be solved with the connection string.我知道还有很多其他类似的问题,其中大部分似乎都可以通过连接字符串解决。 I have tried almost ALL of the different ways you can string up a connection string.我已经尝试了几乎所有可以串起连接字符串的不同方法。 This is what i last tried (credentials have been changed to random letters):这是我上次尝试的(凭据已更改为随机字母):

connectionData = @"Server = eu-cd-steel-west-01.cleardb.net; Port = 3306; Database = heroku_555555555; Uid = b7039sldk253; Pwd = e3502ldks;";

The error I am getting happens when I run this:当我运行这个时,我得到的错误发生了:

connection = new MySqlConnection(connectionData);
connection.Open();

Error:错误:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
 ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at DatabaseTesting.DataBaser.connect() in C:\Users\surf.user\source\repos\DatabaseTesting\DatabaseTesting\DataBaser.cs:line 38

I understand there are SSL credentials and all sorts of stuff, but I am lead to believe that doesn't matter as I didn't have to configure anything special to connect on workbench.我知道有 SSL 凭证和各种各样的东西,但我相信这并不重要,因为我不必配置任何特殊的东西来连接工作台。 Is there anything extra I need to do to successfully open the ClearDB connection on C#?我需要做些什么才能在 C# 上成功打开 ClearDB 连接?

I suspect you're running into this known bug in Oracle's MySQL Connector/NET: bug 97448 .我怀疑您在 Oracle 的 MySQL Connector/NET 中遇到了这个已知错误: bug 97448 (I can't resolve the domain name you gave in the question, but if it resolves to more than one A record then that will trigger the bug.) (我无法解析您在问题中提供的域名,但如果它解析为多个A记录,则会触发错误。)

The fix is to uninstall the MySql.Data NuGet package and install MySqlConnector instead: https://www.nuget.org/packages/MySqlConnector/修复方法是卸载MySql.Data NuGet 包并安装MySqlConnectorhttps : //www.nuget.org/packages/MySqlConnector/

This supports the same API as MySql.Data, so it should be a drop-in replacement.这支持与 MySql.Data 相同的 API,因此它应该是一个替代品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM