When I try to open the connection an error occurred and say:
System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
This is the part of code:
MySqlConnection _Conn;
public void Conectar()
{
new I18N.West.CP1250();
string SC;
SC = "server = XXX; Port = 3306; database = XXX; user id = XXX; password = XXX; charset = utf8";
_Conn = new MySqlConnection(SC);
_Conn.Open();
}
If you problem ocorred with Xamarin, you should do:
1) Remove Reference Mysql Data
2) Add Reference Xamarin.Mysql
You can keep yours calls (using MySql.Data.MySqlClient;)
It sounds like the MySql.Data.MySqlClient.Replication.ReplicationManager
static constructor is trying to initialise the System.Configuration.ConfigurationManager
class, which isn't supported on Xamarin Android.
To avoid this, you could use an alternative MySQL client library that doesn't have that dependency, such as MySqlConnector on NuGet.
来源:https://stackoverflow.com/questions/50137205/androidapp-and-mysqlconnection-didnt-work-connection-open