Problem with mysql connection in C #

2

I created a connection class for my application in Xamarin, but every time I try to connect it 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 can be? The information passed from server, database, user and password, are correct, already checked.

    
asked by anonymous 20.08.2016 / 01:06

1 answer

3

See, there may be a concept problem there. It is not safe to access a database directly from an app, so we created an Api bus that exposes information and has a security layer, be it a JWT, oAuth, etc. Unless you have full control of your App environment, avoid that.

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

    
13.03.2017 / 18:52