Universal App MySQLConnector Queue execution error

2019-09-01 09:42发布

问题:

I try to Execute a queue to my database on my vserver with PHPAdmin and i get the

Exception:

Code:

        static string server = "999.999.999.235";
    static string database = "admin_";
    static string user = "root";
    static string pswd = "secret";

    public static void login()
    {
        string connectionString = "Server = " + server + ";database 
        = "+ database + ";uid = " + user + ";password = " + pswd + ";" + "SslMode=None;" + "CharSet=utf8;";
        using (MySqlConnection connection = new 

    MySqlConnection(connectionString))
        {
            connection.Open();
            MySqlCommand checkLogin = new MySqlCommand("SELECT * FROM `UserData`;");
            using (MySqlDataReader reader = checkLogin.ExecuteReader())
            {
                reader.Read();
                string hash = reader.GetString("UserName");
                string salt = reader.GetString("Workbench");

The Exception is thrown at:

MySqlCommand checkLogin = new MySqlCommand("SELECT * FROM UserData;");

I tried it with UserData and UserData with and without ; same Exception. On the Server the Queue is working fine.

Question: Is the queue wrong or do I forget a configuration on the server ?

回答1:

The Problem was, that I forgot to set the connection for the command

connection.Open();
MySqlCommand checkLogin = new MySqlCommand("SELECT * FROM `UserData`",connection);

After adding the connection, all is working fine.