首页 > 解决方案 > 我在将我的在线托管 MySQL 数据库与我的 C# 应用程序连接时遇到问题

问题描述

我在 000webhost.com 上有一个免费托管的数据库,我正在尝试将此数据库连接到我的 C# 应用程序。当我在 000webhost 上创建数据库时,它给了我在构建连接字符串时使用的这张表 在此处输入图像描述

这是我的连接字符串

Server=99.000webhost.io; Database=db_name_that_in_the_table; port=3306; Uid=username_that_in_the_table; Pwd=the_password_i_used_in_phpmyadmin; SSLMode=Preferred

这是我的 C# 代码

 try
        {
            string myconn = "Server=99.000webhost.io; Database=db_name_that_in_the_table; port=3306; Uid=username_that_in_the_table; Pwd=the_password_i_used_in_phpmyadmin; SSLMode=Preferred";
            MySqlConnection conn = new MySqlConnection(myconn);
            conn.Open();
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

当我尝试建立连接时出现此错误

无法连接到任何指定的 MySQL 主机。

PS:我从 phpMyAdmin 的变量选项卡中获得了主机名或服务器名和端口。

问题是什么以及如何解决?提前致谢。

标签: c#mysql

解决方案


问题是 000webhost.com 不支持 MySQL 远程连接。感谢@Uueerdo,他向我指出了谷歌。


推荐阅读