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