Problem with Mysql connection in C#

Asked

Viewed 223 times

2

I created a connection class for my application in Xamarin, but every time I try to connect throws this exception:

"The type initializer for 'Mysql.Data.Mysqlclient.Replication.Replicationmanager' threw an Exception"

Follow the example code

private static MySqlConnection _conexao = new MySqlConnection();

public void Conectar()
{
      _conexao.ConnectionString = string.Format("server={0};database={1};uid={2}; pwd={3}", Server, Database, Usuario, Senha);
      try
      {
          _conexao.Open();
      }
      catch (Exception e)
      {
          Console.WriteLine(e.ToString());
      }
 }

Does anyone know what it might be? Past server information, database, user and password, are correct, I’ve checked.

  • Go on ProjectPropertiesDebug and check the option Enable Native code debbuging. Run the program again.

  • In the source code, it looks like it’s that line exception.

  • I couldn’t find this option in my VS, it doesn’t have a Debug tab.

1 answer

3

You see, there may be a problem of concept there. It’s not safe to access a database directly from an app, so we’ve created an Api bus that exposes information and has a security layer, whether it’s a JWT, the Uth, etc. Unless you have full control of your App environment, avoid this.

About the error itself, if your server is on the same machine, something like Localhost will possibly not work, the emulator does not identify localhost as a valid port. Each emulator translated in a different way, Genymotion for example, accesses Localhost by ip 10.0.3.2, the default emulator accesses via 10.0.2.2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.