时间:2021-07-01 10:21:17 帮助过:4人阅读
好了 我们开始调用 我们参考官方的代码实例
C#调用MySqlBackup.dll 备份Mysql数据库
1 string constring = "server=localhost;user=root;pwd=qwerty;database=test;"; 2 string file = "C:\\backup.sql"; 3 using (MySqlConnection conn = new MySqlConnection(constring)) 4 { 5 using (MySqlCommand cmd = new MySqlCommand()) 6 { 7 using (MySqlBackup mb = new MySqlBackup(cmd)) 8 { 9 cmd.Connection = conn; 10 conn.Open(); 11 mb.ExportToFile(file); 12 conn.Close(); 13 } 14 } 15 }
1 string constring = "server=localhost;user=root;pwd=qwerty;database=test;"; 2 string file = "C:\\backup.sql"; 3 using (MySqlConnection conn = new MySqlConnection(constring)) 4 { 5 using (MySqlCommand cmd = new MySqlCommand()) 6 { 7 using (MySqlBackup mb = new MySqlBackup(cmd)) 8 { 9 cmd.Connection = conn; 10 conn.Open(); 11 mb.ImportFromFile(file); 12 conn.Close(); 13 } 14 } 15 }
调用看起来很简单 但是现实总比我们想象中要骨干的多 楼主在调用MySqlBackup.dll 备份Discuz数据库时 遇到了如下错误
这错误让楼主百撕不得骑姐
百度上基本查不到这个错误 只搜到一个靠谱点的 搜索关键字 [C# MySQL GUID应包含4个短划线的32位数]
http://www.cnblogs.com/end/archive/2012/12/26/2834068.html
看了这位博主的解释 没太看明白 楼主的领悟力确实不太好
于是不得不再去Google一下 关键字为[C# MySQL Guid should contain 32 digits and 4 dashes]
搜到一个页面 截取里面比较重要的几句话 楼主英语也不是很好 大家将就着看
原页面地址 http://www.christianroessler.net/tech/2015/c-sharp-mysql-connector-guid-should-contain-32-digits-with-4-dashes.html
That error comes from the MySQL-Connector. Everything that is CHAR(36) in your database will be parsed as GUID in .NET. If there is something as ‘‘, null or something that cannot be parsed as GUID the connector throws an Exception.
See https://bugs.mysql.com/bug.php?id=60945
We chose to declare char(36) as always containing guids. If your column can contain nulls, I suggest you use NULL instead of ‘‘ to represent that. If the column is not containing guids, then use char(37) or some other length.
Long story short: add the following to your connection-string to parse CHAR(36) as System.String and not as GUID:
old guids=true;
Here is an example MySQL.NET connection String:
server=localhost;user=root;password=abc123;database=test;old guids=true;
C#使用MysqlBackup.Net 备份MySQL数据库
标签: