Xamarin MySQL connection

Barach

New member
Joined
Jun 3, 2021
Messages
2
Programming Experience
5-10
Hi guys. I am using VS2019 building Android App with Xamarin. Its failing to connect me to any mysql database.
Am usb my phone for debugging. Preferably connecting to my localhost.

Any help?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,386
Location
Chesapeake, VA
Programming Experience
10+
What error code or error message are you getting from the failed connections?
 

Barach

New member
Joined
Jun 3, 2021
Messages
2
Programming Experience
5-10
What error code or error message are you getting from the failed connections?
This is the error I am getting...

"System.TypeInitializationException: 'The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception.'"

C#:
string connString = "Server=db4free.net;Port=3306;database=barachtestingdb;User Id=barachtestingdb;Password=barachtestingdb;charset=utf8";
                MySqlConnection conn = new MySqlConnection(connString);

                if (conn.State == ConnectionState.Closed)
                {
                    try
                    {
                        conn.Open();
                        DisplayAlert("Yeah", "Connection established", "OK");

                    }
                    catch (MySqlException ex)
                    {
                        DisplayAlert("Naaah", "Connection failed: " + ex.Message, "Quit");
                    }
                    finally
                    {

                        conn.Close();
                        DisplayAlert("Finally", "Connection closed", "OK");
                    }

                }

The error is coming on "conn.Open()";
 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,386
Location
Chesapeake, VA
Programming Experience
10+
First hit on Google points to incompatibility between Mono and the default MySql driver. The suggestion was to use a different driver:



The answers in the second like provides an explanation of why the incompatibility exists.
 

NoUserHere

Well-known member
Joined
Sep 5, 2018
Messages
2,138
Programming Experience
10+
Which MySql Library or connector are you using?

And please include a link to them or explain how you referenced the libraries you are using?

Using the MySql connector is the way forward, but you can't just use any version.
 

Neal

Forum Admin
Staff member
Joined
Apr 15, 2011
Messages
165
Location
VA
Programming Experience
10+
I suggest using the nuget package sqlite-net for your database work.

 
Top Bottom