См. Результат теста ниже, и мы также прикрепляем код образца в разделе «Подробности». br />
.Net version: 4.0.30319.42000
Attempting to open connection...
Connection successful!
Error executing query: The given key was not present in the dictionary.
Press any key to continue . . .
Мы попробовали строку подключения:
- server=192.168.56.5;uid=root;port=3306;database=test-source;pwd=mysql_root_password или
- server=192.168.56.5;uid=root;port=3306;database=test-source;charset=utf8mb4;pwd=mysql_root_password
Подробности: < /strong> < /p>
Полный образцы исходного кода: < /p>
using System;
using MySql.Data.MySqlClient;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(".Net version: " + Environment.Version.ToString());
string connectionString = "server=192.168.56.5;uid=root;port=3306;database=test-source;pwd=mysql_root_password";
try
{
using (var connection = new MySqlConnection(connectionString))
{
Console.WriteLine("Attempting to open connection...");
connection.Open();
if (connection.State == System.Data.ConnectionState.Open)
{
Console.WriteLine("Connection successful!");
// Retrieve MySQL version
try
{
string query = "SELECT VERSION();";
using (var command = new MySqlCommand(query, connection))
{
string version = command.ExecuteScalar().ToString();
Console.WriteLine("MySQL Version: " + version);
}
}
catch (Exception ex)
{
Console.WriteLine("Error executing query: " + ex.Message);
}
}
else
{
Console.WriteLine("Failed to open the connection.");
}
}
}
catch (MySqlException ex)
{
Console.WriteLine("MySQL Exception: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("General Exception: " + ex.Message);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... -given-key
Мобильная версия