Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been using visual studio 2019 and was following a tutorial on how to set up an online database. In the first step of making the connection, I got an error saying:

System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.

this error has been solved in previous versions of visual studio but I haven't found anything about it in visual studio 2019.

This is the tutorial I was following: https://youtu.be/FOZ8HNJMXXg I've been searching around for this error and found people having the exact same error in much earlier versions of visual studio. their solution was to turn on "SQL Server Debugging" (See this answer https://stackoverflow.com/a/20788018/11327572 ) I've looked for the option but couldn't find it anywhere. I've also searched for the error in visual studio 2019 but couldn't find anything on it.

        MySqlConnection con = new MySqlConnection("server=db4free.net;port=3306;database=***;User Id=***;Password=***!;charset=utf8");
        try
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open(); //this is the line the break comes up on.
                Log.Debug("MySQL connected", con.ToString()); 
            }
            con.Close();
        }catch(MySqlException ex)
        {
            Log.Debug("MySQL error", ex.ToString());
        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
394 views
Welcome To Ask or Share your Answers For Others

1 Answer

I had the same problem but I solved with this package MySqlConnector

MySqlConnector

Note

If you're using the root user try to create another user with password.

And here's my class I used to connect to MySql.

public class SQLDataAccess
{
    string cs = @"Server=172.20.10.5;Database=TestDB;Uid=Creative;Pwd=123456;";
    public SQLDataAccess()
    {
        try
        {
            connection = new MySqlConnection(cs);
            connection.Open();
        }
        catch (MySqlException Ex)
        {
            Console.WriteLine(Ex.Message);
        }
    }

    private string databaseName = string.Empty;

    public string DatabaseName
    {
        get { return databaseName; }
        set { databaseName = value; }
    }

    public string Password { get; set; }

    private MySqlConnection connection = null;

    public MySqlConnection Connection
    {
        get { return connection; }
    }

    private static SQLDataAccess _instance = null;

    public static SQLDataAccess Instance()
    {
        if (_instance == null)
            _instance = new SQLDataAccess();
        return _instance;
    }

    public bool IsConnect()
    {   
        try
        {
            connection = new MySqlConnection(cs);
            connection.Open();
            return true;
        }
        catch (MySqlException Ex)
        {
            Console.WriteLine(Ex.Message);
            return false;
        }
    }

    public void Close()
    {
        connection.Close();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...