簡體   English   中英

無法連接到任何指定的MySQL主機

[英]Unable to connect to any of the specified MySQL hosts

我知道這是一個簡單的問題,但我找不到錯誤。 我想將數據保存在數據庫中。 我使用Microsoft SQL Server 2008創建了一個名為“ Examen”的數據庫,然后在Visual Studio的應用程序中輸入如下連接字符串:

string connectionstring = @"Data Source=.\sqlexpress;Initial Catalog=Examen;Integrated Security=True";

然后,我使用以下代碼將數據插入“測試”表中:

MySqlConnection connection = new MySqlConnection(connectionstring);
MySqlCommand cmd;
connection.Open();

try
{
  cmd = connection.CreateCommand();
  cmd.CommandText = "Insert into Examen.Test (nom,prenom) values (" + txbnom.Text + "," + txbprenom.Text + ") ";
  cmd.ExecuteNonQuery();
  MessageBox.Show("ok");
}
catch (Exception)
{
  throw;
}
finally
{ 
  if(connection.State == ConnectionState.Open)
  {
    connection.Close();
  }
}

運行此代碼時,打開連接時出現錯誤

Unable to connect to any of the specified MySQL hosts.

您正在混合使用MySQLMSSQL

您確定要連接到MySQL服務器嗎? 如果要連接到MSSQL,請使用http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlconnection(v=vs.110).aspx

您還應該使自己熟悉SQL注入

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM