mysql连接失败?错误?沙马林和c#

hec6srdp  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(335)

所以我一直在为实习制作这个登录应用程序(在android上,vis studio 17中有xamarin),我基本上做的就是当访客进来时,他们登录,当按下登录按钮时,页面打开,因此,让他们把他们的信息,然后(页面上他们把他们的信息是我要发布的),它发送他们的数据到数据库,以及发送回主页(在那里应用程序启动)。我可以进入一个页面,上面有他们所有的详细信息等等,但是当我按sign-in时,我发现了这个错误:
以下是我的密码:用于登录:

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Collections.Specialized;
using MySql.Data.MySqlClient;

namespace MRC_Sign_In_Sheet
{
    public class OnSignInEvenArgs : EventArgs
    {
        private string txtName;
        private string txtRepresent;
        private string txtToSee;
        private string txtPurpose;
        private string classification;
        private string citizenStatus;       

        public string Name
        {
            get { return txtName; }
            set { txtName = value; }
        }
        public string Represent
        {
            get { return txtRepresent; }
            set { txtRepresent = value; }
        }
        public string ToSee
        {
            get { return txtToSee; }
            set { txtToSee = value; }
        }
        public string Purpose
        {
            get { return txtPurpose; }
            set { txtPurpose = value; }
        }
        public string CitizenStatus
        {
            get { return citizenStatus; }
            set { citizenStatus = value; }
        }
        public string Classification
        {
            get { return classification; }
            set { classification = value; }
        }

        public OnSignInEvenArgs(string name, string represent, string tosee, string purpose, string citizenstatus, string classification) : base()
        {
            Name = name;
            Represent = represent;
            ToSee = tosee;
            Purpose = purpose;
            CitizenStatus = citizenstatus;
            Classification = classification;
        }
    }

    class SignInDialog : DialogFragment
    {
        Button signInBack;
        RadioButton radCitizen;
        RadioButton radNotCitizen;
        RadioButton radClassified;
        RadioButton radUnclassified;
        private EditText txtName;
        private EditText txtRepresent;
        private EditText txtToSee;
        private EditText txtPurpose;
        private string classification;
        private string citizenStatus;
        public event EventHandler<OnSignInEvenArgs> nOnSignInComplete;

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.SignIn, container, false);

            txtName = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtName);
            txtRepresent = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtRepresent);
            txtToSee = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtToSee);
            txtPurpose = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtPurpose);
            radCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radCitizen);
            radNotCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radNotCitizen);
            radClassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radClassified);
            radUnclassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radUnclassified);
            signInBack = view.FindViewById<Button>(MRC_Sign_In_Sheet.Resource.Id.signInBack);

            if(radCitizen.Checked)
            {
                citizenStatus = "Citizen";
            }
            else if(radNotCitizen.Checked)
            {
                citizenStatus = "Not A Citizen";
            }
            if(radClassified.Checked)
            {
                classification = "Classified";
            }
            else if (radUnclassified.Checked)
            {
                classification = "Unclassified";
            }
            signInBack.Click += SignIn_Click;           
            return view;
        }

        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_Animations;
        }

        void SignIn_Click(object sender, EventArgs e)
        {

            int badgeNum = new Random().Next(100000, 999999);
            DateTime dateTimeSignIn = DateTime.Now;

            MySqlConnection con;
            string connectionstring = "Server=db4free.net;Port=3306;Database=mrcwebappdb;User Id=dbeditor;Password=Monster001359%;charset=utf8";
            con = new MySqlConnection(connectionstring);

            con.Open();                                
            MySqlCommand cmd = new MySqlCommand("INSERT INTO visitormanagement(visitorName,visitorBadgeNumber,visitorRepresent,visitorToSee,visitorPurpose,visitorCitizenship,visitorClassification,visitorSignIn) VALUES(@visitorName,@visitorBadgeNumber,@visitorRepresent,@visitorToSee,@visitorPurpose,@visitorCitizenship,@visitorClassification,@visitorSignIn)", con);
            cmd.Parameters.AddWithValue("@visitorName", txtName.Text);
            cmd.Parameters.AddWithValue("@visitorBadgeNumber", badgeNum.ToString());
            cmd.Parameters.AddWithValue("@visitorRepresent", txtRepresent.Text);
            cmd.Parameters.AddWithValue("@visitorToSee", txtToSee.Text);
            cmd.Parameters.AddWithValue("@visitorPurpose", txtPurpose.Text);
            cmd.Parameters.AddWithValue("@visitorCitizenship", citizenStatus);
            cmd.Parameters.AddWithValue("@visitorVlassification", classification);
            cmd.Parameters.AddWithValue("@visitorSignIn", dateTimeSignIn.ToString());
            cmd.ExecuteNonQuery();

            nOnSignInComplete.Invoke(this, new OnSignInEvenArgs(txtName.Text, txtRepresent.Text, txtToSee.Text, txtPurpose.Text, citizenStatus, classification));

            this.Dismiss(); //This brings me back to the home page
        }
    }
}

这是我当前得到的错误:未处理的异常:
system.typeinitializationexception:“mysql.data.mysqlclient.replication.replicationmanager”的类型初始值设定项引发异常。发生
顺便说一句:我使用这个db4free站点只是为了测试,因为如果我把它放在本地托管的db中,位置就是服务器的特定地址。我意识到这个错误(如果我没有弄错的话)与连接被打开的时候有关,或者我可能直接完全错了。任何帮助都将不胜感激。
快速更新:所以我意识到我是在用一种咒骂式的反向方法将它连接到数据库。现在它连接,但提交时,我得到这个新的错误。以下是截至目前的代码(第一个是登录,第二个是注销)。

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Collections.Specialized;
using MySqlConnector;
using MySql.Data.MySqlClient;

namespace MRC_Sign_In_Sheet
{   
    class SignInDialog : DialogFragment
    {        
        Button signInBack;
        RadioButton radCitizen;
        RadioButton radNotCitizen;
        RadioButton radClassified;
        RadioButton radUnclassified;
        private EditText txtName;
        private EditText txtRepresent;
        private EditText txtToSee;
        private EditText txtPurpose;
        private string classification;
        private string citizenStatus;

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.SignIn, container, false);

            txtName = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtName);
            txtRepresent = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtRepresent);
            txtToSee = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtToSee);
            txtPurpose = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtPurpose);
            radCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radCitizen);
            radNotCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radNotCitizen);
            radClassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radClassified);
            radUnclassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radUnclassified);
            signInBack = view.FindViewById<Button>(MRC_Sign_In_Sheet.Resource.Id.signInBack);

            if (radCitizen.Checked)
            {
                citizenStatus = "Citizen";
            }
            else if (radNotCitizen.Checked)
            {
                citizenStatus = "Not A Citizen";
            }
            if (radClassified.Checked)
            {
                classification = "Classified";
            }
            else if (radUnclassified.Checked)
            {
                classification = "Unclassified";
            }
            signInBack.Click += SignIn_Click;
            return view;
        }

        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_Animations;
        }

        void SignIn_Click(object sender, EventArgs e)
        {
            int badgeNum = new Random().Next(100000, 999999);
            DateTime dateTimeSignIn = DateTime.Now;

            MySqlConnection con = new MySqlConnection("Server=db4free.net;Port=3306;Database=mrcwebappdb;Uid=dbeditor;pwd=Monster001359%;");  
            string insertQuery = "INSERT INTO visitormanagement(visitorName, visitorBadgeNumber, visitorRepresent, visitorToSee, visitorPurpose, visitorCitizenship, visitorClassification, visitorSignIn) VALUES('" + txtName.Text + "','" + badgeNum + "'," + txtRepresent.Text + "','" + txtToSee.Text + "','" + txtPurpose.Text + "','" + citizenStatus + "','" + classification + "','" + dateTimeSignIn + ")";

            con.Open();
            MySqlCommand command = new MySqlCommand(insertQuery, con);
            command.ExecuteNonQuery();
            con.Close();

            this.Dismiss();
        }
    }
}

用于注销:

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Collections.Specialized;
using MySqlConnector;
using MySql.Data.MySqlClient;

namespace MRC_Sign_In_Sheet
{

    class SignOutDialog : DialogFragment
    {
        Button signOutBack;
        private EditText signOutName;
        private EditText signOutBadge;

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.SignOut, container, false);

            signOutName = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.signOutName);
            signOutBadge = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.signOutBadge);
            signOutBack = view.FindViewById<Button>(MRC_Sign_In_Sheet.Resource.Id.signOutBack);

            signOutBack.Click += SignOut_Click;

            return view;
        }

        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_Animations;
        }

        void SignOut_Click(object sender, EventArgs a)
        {
            DateTime dateTimeSignOut = DateTime.Now;

            MySqlConnection con = new MySqlConnection("Server=db4free.net;Port=3306;Database=mrcwebappdb;Uid=dbeditor;pwd=Monster001359%;");
            string insertQuery = "INSERT INTO visitormanagementsignout(visitorName, visitorBadgeNumber, visitorSignOutTime) VALUES('" + signOutName.Text + "','" + signOutBadge + "'," + dateTimeSignOut + ")";

            con.Open();
            MySqlCommand command = new MySqlCommand(insertQuery, con);
            command.ExecuteNonQuery();
            con.Close();

            this.Dismiss();
        }   
    }
}

我在输出“未处理的异常:
system.aggregateexception:发生了一个或多个错误。”之后没有更多信息。我查看了调试,这是出现的我的登录和注销的集合。下面是发生错误的地方的调试。

On Sign In
-----------------------------------------------------
Unhandled Exception:

System.AggregateException: One or more errors occurred.

05-21 17:52:39.623 D/Mono    (12745): Image addref System.Runtime.Serialization[0xf8223678] -> System.Runtime.Serialization.dll[0xf8222e88]: 2
05-21 17:52:39.623 D/Mono    (12745): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
05-21 17:52:39.623 D/Mono    (12745): Assembly System.Runtime.Serialization[0xf8223678] added to domain RootDomain, ref_count=1
05-21 17:52:39.624 D/Mono    (12745): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:52:39.625 D/Mono    (12745): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:52:39.625 D/Mono    (12745): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
05-21 17:52:39.625 D/Mono    (12745): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
05-21 17:52:39.626 D/Mono    (12745): Assembly Ref addref Mono.Android[0xf7a39d78] -> System.Runtime.Serialization[0xf8223678]: 2
05-21 17:52:39.626 D/Mono    (12745): Assembly Ref addref System.Runtime.Serialization[0xf8223678] -> mscorlib[0xf79f65c8]: 23
05-21 17:52:43.443 I/Kernel  (12745): [303182.603650] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc0290649c0, buf=ffffffc0049b2800, ref=4, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel  (12745): [303182.603679] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc003519f80, buf=ffffffc038f00500, ref=2, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel  (12745): [303182.603696] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc02f609540, buf=ffffffc039616000, ref=4, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel  (12745): [303182.603741] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc03a96f080, buf=ffffffc039616e00, ref=2, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel  (12745): [303182.603757] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc029064c00, buf=ffffffc03b5b2b00, ref=8, size=3833856, kmap=0

______________________________________________________
On Sign Out
------------------------------------------------------
Unhandled Exception:

System.AggregateException: One or more errors occurred.

05-21 17:51:25.292 D/Mono    (12603): Image addref System.Runtime.Serialization[0xf81e7578] -> System.Runtime.Serialization.dll[0xf8213c30]: 2
05-21 17:51:25.292 D/Mono    (12603): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
05-21 17:51:25.292 D/Mono    (12603): Assembly System.Runtime.Serialization[0xf81e7578] added to domain RootDomain, ref_count=1
05-21 17:51:25.293 D/Mono    (12603): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:51:25.294 D/Mono    (12603): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:51:25.294 D/Mono    (12603): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
05-21 17:51:25.294 D/Mono    (12603): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
05-21 17:51:25.294 D/Mono    (12603): Assembly Ref addref Mono.Android[0xf7a39ac0] -> System.Runtime.Serialization[0xf81e7578]: 2
05-21 17:51:25.295 D/Mono    (12603): Assembly Ref addref System.Runtime.Serialization[0xf81e7578] -> mscorlib[0xf79f6318]: 23
Loaded assembly: System.Runtime.Serialization.dll [External]
05-21 17:51:31.753 I/Kernel  (12603): [303110.913251] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc01c34b080, buf=ffffffc02ec3ad00, ref=4, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel  (12603): [303110.913288] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc031b94400, buf=ffffffc03703e600, ref=4, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel  (12603): [303110.913313] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc046020d00, buf=ffffffc0370c2a00, ref=2, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel  (12603): [303110.913339] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc046020840, buf=ffffffc0370c2c00, ref=2, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel  (12603): [303110.913364] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc01c1f47c0, buf=ffffffc03b5b2b00, ref=8, size=3833856, kmap=0

到底是什么原因造成的?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题