标签:
首先 声明这篇博文没有什么技术水平 希望各位大神口下留情
好的 咱们进入主题
开场介绍一下这个MysqlBackup.Net dll
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 }
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.
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数据库
标签:
原文地址:http://www.cnblogs.com/dsnixi/p/4951241.html