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?
 
What error code or error message are you getting from the failed connections?
 
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:
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.
 
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.
 
Back
Top Bottom