如何使用windows iot core连接rasberry pi 3中的在线数据库?

时间:2018-02-28 08:00:02

标签: database raspberry-pi

我创建了一个连接数据库的测试程序(UWP应用程序)。起初,我尝试使用本地服务器xampp将其连接到本地数据库,并且它与此代码配合良好:

            server = "166.62.27.167";
            database = "doorlock_system";
            uid = "philipplaz";
            password = "philipp123";

            string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";SslMode=None";

            connection = new MySqlConnection(@connectionString);

            System.Text.EncodingProvider ppp;
            ppp = System.Text.CodePagesEncodingProvider.Instance;
            System.Text.Encoding.RegisterProvider(ppp);

            if (connection.State == MySql.Data.MySqlClient.ConnectionState.Closed)
            {

                try { connection.Open(); }
                catch (MySqlException e)
                {
                    var dialog1 = new MessageDialog(e.ToString());
                    await dialog1.ShowAsync();

                }

                MySqlCommand commandInsert = new MySqlCommand("INSERT INTO user(username) VALUES (@username)", connection);
                commandInsert.Parameters.AddWithValue("@username", userName);
                commandInsert.ExecuteNonQuery();
                commandInsert.Parameters.Clear();
                var dialog = new MessageDialog("Username Inserted!");
                await dialog.ShowAsync();
            }

成功连接后,我尝试使用GoDaddy作为网络主机连接到在线数据库,但不幸的是我无法连接。这是我对上述程序所做的更改 server = "166.62.27.167"; database = "doorlock_system"; uid = "philipplaz"; password = "philipp123";

你能帮我辨认一下这个问题吗?我真的需要你的帮助。非常感谢你

0 个答案:

没有答案