我想以我的計算機名稱作為主機連接到 mysql。我收到此錯誤:
無法連接到任何指定的 mysql 主機
當我使用localhost或127.0.0.1更改主機時。它作業正常。
我使用我的計算機名稱直接在 mysql 作業臺中測驗連接:COMP-18TN。MySQL Workbench 可以連接到該服務器。但不是我的 c# 代碼。
你發現如下我的代碼:
string host = "COMP-18TN";
string DatabaseName = "Cars_DB";
string UserName ="root_name";
string Password ="pass";
string connString = string.Format("Server={0}; database={1}; UID={2}; password={3}",
host, DatabaseName, UserName, Password);
MySqlConnection conn = new MySqlConnection(connString);
try
{
conn.Open();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
uj5u.com熱心網友回復:
您可以嘗試在hosts位于以下位置的檔案中添加一個條目C:\Windows\System32\drivers\etc\hosts:
127.0.0.1 COMP-18TN
這樣,您的計算機名稱將決議為您知道有效的本地 IP。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/351135.html
