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

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

问题描述

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

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

此错误已在以前版本的 Visual Studio 中解决,但我在 Visual Studio 2019 中没有找到任何相关信息.

这是我关注的教程:

<块引用>

注意

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

这是我用来连接到 MySql 的类.

公共类 SQLDataAccess{string cs = @"Server=172.20.10.5;Database=TestDB;Uid=Creative;Pwd=123456;";公共 SQLDataAccess(){尝试{connection = new MySqlConnection(cs);连接.打开();}捕获(MySqlException Ex){Console.WriteLine(Ex.Message);}}私有字符串 databaseName = string.Empty;公共字符串数据库名称{得到 { 返回数据库名称;}设置 { 数据库名称 = 值;}}公共字符串密码{获取;放;}私有 MySqlConnection 连接 = null;公共 MySqlConnection 连接{得到{返回连接;}}私有静态 SQLDataAccess _instance = null;公共静态 SQLDataAccess 实例(){如果(_instance == null)_instance = new SQLDataAccess();返回_实例;}public bool IsConnect(){尝试{connection = new MySqlConnection(cs);连接.打开();返回真;}捕获(MySqlException Ex){Console.WriteLine(Ex.Message);返回假;}}公共无效关闭(){连接.关闭();}}

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天全站免登陆