ReplicationManager在打开连接时引发异常 [英] ReplicationManager threw an exception on opening a connection

查看:103
本文介绍了ReplicationManager在打开连接时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Visual Studio 2019,并正在关注有关如何建立在线数据库的教程.在建立连接的第一步中,我收到一条错误消息:

System.TypeInitializationException:"MySql.Data.MySqlClient.Replication.ReplicationManager"的类型初始值设定项引发了异常.

此错误已在Visual Studio的早期版本中得到解决,但我在Visual Studio 2019中未发现任何有关此错误的信息.

这是我正在关注的教程:

注意

如果您使用的是root用户,请尝试使用密码创建另一个用户.

这是我用来连接MySql的类.

 公共类SQLDataAccess{字符串cs = @"Server = 172.20.10.5; Database = TestDB; Uid = Creative; Pwd = 123456;";公共SQLDataAccess(){尝试{连接=新的MySqlConnection(cs);connection.Open();}抓(MySqlException Ex){Console.WriteLine(Ex.Message);}}私有字符串databaseName = string.Empty;公用字符串DatabaseName{得到{return databaseName;}设置{databaseName = value;}}公共字符串密码{get;放;}私人MySqlConnection连接= null;公共MySqlConnection连接{得到{返回连接;}}私有静态SQLDataAccess _instance = null;公共静态SQLDataAccess Instance(){如果(_instance == null)_instance = new SQLDataAccess();返回_instance;}公共布尔IsConnect(){尝试{连接=新的MySqlConnection(cs);connection.Open();返回true;}抓(MySqlException Ex){Console.WriteLine(Ex.Message);返回false;}}公共无效Close(){connection.Close();}} 

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

解决方案

I had the same problem but I solved with this package 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();
    }
}

这篇关于ReplicationManager在打开连接时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆