0

I can't connect to my remote MySQL database with my MAUI application which I start from a mobile device. But when I debug the application with "Windows Machine" everything is fine.

Can anyone please help me? Here is my code:

using MySqlConnector;

namespace Tinder4Nerds.Models
{
    static class DatabaseModel
    {
        private static MySqlConnection connection = null;

        private static void ConnectToDatabase()
        {
            try
            {
                string dbServer = "MY IP";
                string dbName = "MY DB";
                string dbUser = "MY USER";
                string dbPassword = "MY PASSWORD";

                var builder = new MySqlConnectionStringBuilder
                {
                    Server = dbServer,
                    Database = dbName,
                    UserID = dbUser,
                    Password = dbPassword
                };

                connection = new MySqlConnection(builder.ConnectionString);
                connection.Open();
                if (connection == null)
                {
                    Console.WriteLine("Error");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public static bool VerifyLogin(string username, string password)
        {
            string pwd = string.Empty;
            if (connection == null)
            {
                ConnectToDatabase();
            }
            var command = connection.CreateCommand();
            command.CommandText = "SELECT password FROM user WHERE username = '" + username +     
                "';";
            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                pwd = reader["password"].ToString();
                if(password == pwd)
                {
                    return true;
                } else
                {
                    return false;
                }
            }
            return false;
        }
    }
}

The connection to the remote MySQL server is unsecured (perhaps this may help)

Exception e Errormessage:

{MySqlConnector.MySqlException (0x80004005): SSL Authentication Error
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> Interop+AndroidCrypto+SslException: Exception of type 'Interop+AndroidCrypto+SslException' was thrown.

Both my Desktop PC and my mobile devices are on the same network. And when my mobile device isn't in my home network it's the same - doesn't work.

Perhaps someone has a hint for me

Thanks

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
DaveR
  • 63
  • 1
  • 10
  • You are failing SSL which means to code is making an HTTPS (not HTTP) connection between the client (mobile device) and server (windows machine). SSL really means TLS (SSL is obsolete). TLS uses a certificate and the certificate has to be manually loaded on both the client and server before code is run. Since you are working when using windows machine it means the certificate is not on the Maui Device. See : https://stackoverflow.com/questions/4461360/how-to-install-trusted-ca-certificate-on-android-device – jdweng Apr 01 '23 at 11:07
  • Thx for your reply. DB server is linux server – DaveR Apr 01 '23 at 11:16
  • Here is another link : https://www.entrust.com/knowledgebase/ssl/ssltls-certificate-installation-instructions-apache-linux – jdweng Apr 01 '23 at 15:35

0 Answers0