AndroidApp and MySqlConnection didn't work connection.open

此生再无相见时 提交于 2019-11-26 23:40:49

问题


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();
}

回答1:


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;)




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!