[英]Connecting with remote mysql database, getting the error “Unable to connect to any of the specified MySQL hosts”
我正在創建一個連接到遠程mysql數據庫的應用程序到一些cpanel帳戶。 我在cpanel帳戶上創建了數據庫,並為其定義了用戶名和密碼。 我正在使用MysqlConnector。 到目前為止,我已經編寫了以下代碼:
using MySql.Data.MySqlClient;
MySqlConnection c = new MySqlConnection("SERVER = 64.191.12.54; DATABASE = alyataco_test4application; User ID = xxxxxxxx; PASSWORD = xxxxxxxx");
c.Open();
但是我得到了錯誤:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.
我還看到使用Visual C#連接到遠程MySQL數據庫,但也沒有幫助
你的連接字符串似乎錯了。 嘗試:
MySqlConnection c = new MySqlConnection("server=64.191.12.54; database=alyataco_test4application; uid=xxxxxxxx; pwd=xxxxxxxx");
有關更多連接字符串示例,請參見http://www.connectionstrings.com/mysql 。
有可能您的主機不允許遠程連接到數據庫服務器。 簡單的方法是將項目部署到服務器並且它是否有效。
右鍵單擊解決方案資源管理器中的項目名稱。 並選擇“添加引用”,然后從可用文件中選擇“MySQL.data”並添加它。 現在我認為它不會給出錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.