我试图连接到远程MySql数据库以提取一些数据。我安装了MySqlConnector,但我的代码似乎不起作用。它永远不会从try
块中消失(它永远不会打印Connection OK
)。它能是什么?
string server = "serverIpAddress";
string database = "dbName";
string uid = "userName";
string password = "****";
string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
MySqlConnection myConnection = new MySqlConnection(connectionString);
try
{
Console.WriteLine("Trying to open");
myConnection.Open();
Console.WriteLine("Connection OK");
}
catch (Exception e)
{
Console.WriteLine(e.InnerException);
}
Console.ReadKey();