ReplicationManager在打开连接时引发异常

编程入门 行业动态 更新时间:2024-10-24 17:26:02
本文介绍了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: 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 stackoverflow/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;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在打开连接时引发异常

本文发布于:2023-11-17 07:31:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   ReplicationManager

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!