Answer the question
In order to leave comments, you need to log in
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
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();
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question