我正在检查Xamarin.android的在线数据库的连接,但此错误不断出现。.im计划将其连接到rasp pi数据库以供我的研究项目使用。.pls帮助
using Android.App;
using Android.OS;
using Android.Widget;
using MySql.Data.MySqlClient;
using System;
using System.Data;
namespace sqq
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
private EditText urs, pss;
private Button sin;
private TextView suc;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
sin = FindViewById<Button>(Resource.Id.button1);
urs = FindViewById<EditText>(Resource.Id.textView1);
pss = FindViewById<EditText>(Resource.Id.textView2);
suc = FindViewById<TextView>(Resource.Id.textView3);
sin.Click += Sin_Click;
}
private void Sin_Click(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection("Server=db4free.net; Port=3306; Database=rolandvill; User Id=roland11; Password=roland123;charset=utf8");
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
suc.Text = "Success";
}
}
catch (MySqlException ex)
{
suc.Text = ex.ToString();
}
finally
{
con.Close();
}
}
}
}
我一直在尝试这里看到的所有解决方案ive,但是都没有用。
这里是我的activity_main.axml的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:text="UserName"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/textView1" />
<EditText
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:id="@+id/textView2" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView2"
android:id="@+id/button1" />
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/button1"
android:id="@+id/textView3" />
</RelativeLayout>