F
F
firstKronus2020-07-20 17:03:21
Android
firstKronus, 2020-07-20 17:03:21

I get an error when accessing the MySQL database on Xamarin.Android, how to fix it?

Hello!
When accessing the database, the following error occurs. The problem occurs when connecting, but what exactly is the error, I still do not understand.
Did according to this guide: https://www.youtube.com/watch?v=FOZ8HNJMXXg

Program code
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System.Data;
using MySql.Data.MySqlClient;

namespace TestSQLite
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {

        private EditText etUsername, etPassword;
        private Button btnInsert;
        private TextView txtSysLog;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            etUsername = FindViewById<EditText>(Resource.Id.XetUsername);
            etPassword = FindViewById<EditText>(Resource.Id.XetPassword);
            btnInsert = FindViewById<Button>(Resource.Id.XbtnInsert);
            txtSysLog = FindViewById<TextView>(Resource.Id.XtxtSysLog);

            btnInsert.Click += BtnInsert_Click;
        }

        private void BtnInsert_Click(object sender, System.EventArgs e)
        {
            MySqlConnection con = new MySqlConnection("server = db4free.net; port = 3306; database = kronustest; user id = kronus; password = artem123; charset = utf8");

            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                    txtSysLog.Text = "Successfully connected";
                }
            }
            catch (MySqlException ex)
            {
                txtSysLog.Text = ex.ToString();
            }
            finally
            {
                con.Close();
            }

        }
    }
}

Screenshots of errors and database:
5f15a2c7d036b319040283.png
5f15a2d46cb83563497908.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question