C # using Mysqlbackup.net to back up MySQL database

Source: Internet
Author: User

First of all, there is no technical skill in this blog post, and I hope you will have mercy.

Okay, let's get to the subject.

Let's introduce this mysqlbackup.net DLL.

is a foreign open source Works official website https://mysqlbackupnet.codeplex.com/I here to provide the latest official version 2.0.9.2 there will be two folders inside the binaries inside the class library is divided into various. NET versions so Urce code inside is the source code interested students can download their own code click Download Mysqlbackup.net because my project version is 4.0, so to refer to 4.0 of the Library of course Reference 2.0 and 3.5 is not a problem here to remind: MySqlBackup.dll is dependent on MySql.Data.dll, so the referenceMySqlBackup.dll also refer to theMySql.Data.dllOkay, let's start calling our reference to the official Code instance C # callMySqlBackup.dll back up the MySQL database
  1. 1 stringConstring ="server=localhost;user=root;pwd=qwerty;database=test;";2 stringFile ="C:\\backup.sql";3 using(Mysqlconnection conn =Newmysqlconnection (constring))4 {5     using(Mysqlcommand cmd =NewMysqlcommand ())6     {7         using(Mysqlbackup MB =Newmysqlbackup (cmd))8         {9Cmd. Connection =Conn;Ten Conn. Open (); One MB. Exporttofile (file); A Conn. Close (); -         } -     } the}


C # callsMySqlBackup.dllRestoreMySQL Database
1 stringConstring ="server=localhost;user=root;pwd=qwerty;database=test;";2 stringFile ="C:\\backup.sql";3 using(Mysqlconnection conn =Newmysqlconnection (constring))4 {5     using(Mysqlcommand cmd =NewMysqlcommand ())6     {7         using(Mysqlbackup MB =Newmysqlbackup (cmd))8         {9Cmd. Connection =Conn;Ten Conn. Open (); One MB. ImportFromFile (file); A Conn. Close (); -         } -     } the}

The call seems simple but the reality is more than we thought the backbone of the landlord in the callMySqlBackup.dll The following error was encountered while backing up the Discuz database
This error let the landlord hundred tear not to ride sister Baidu on the basic can't find this error only found a point of search keywords [C # MySQL GUID should contain 4 dashes of 32-digit]http://www.cnblogs.com/end/archive/2012/12/26/ 2834068.html Read the blogger's explanation not too see the landlord's understanding is really not very good so I have to go to Google a keyword for the [C # MySQL Guid should contain digits and 4 dashes] search a page Face interception inside more important words, landlord English is not very good everyone will see the original page address 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 (*) in your database would be parsed as GUID in. NET. If there is something as ", null or something that cannot be parsed as GUID of the connector throws an Exception.

See https://bugs.mysql.com/bug.php?id=60945

The idea is this: the error is Mysql-connector caused by (MySql.Data.dll), all fields in the char (36) format in MySQL will be processed into the GUID type in. NET .If the char (36) field contents are ' null ' or other things that cannot be converted to a GUID type will throw an exception. Combined with what the blogger wrote just now, it seems that we know what the problem is. This article also provides several solutions
Char (as "ischar"or someother length.)
 

Long story Short:add The following to your connection-string to parse CHAR (*) as System.String and not as GUID:

Old guids=true;

Here's an example mysql.net connection String:

Server=localhost;user=root;password=abc123;database=test;old guids=true;

The workaround probably means this: 1. If you MySQL database char (36) field content does not contain a GUID it is recommended to change the char length or to another type 2. If you do not want to change the field type, you can add an old guids=true to the link string; Include in the link string as recommendedOld guids=true; Post char (36) will be treated as a stringrebuild again debug OK again throughThe first time to write a blog slightly verbose but here the landlord wants to emphasize is to solve the problem of ideas.It 's better to try and practice more.If there's a big God who thinks there's something wrong with that, you're welcome to shoot bricks.All right, this is the force of the day, thank you.

C # using Mysqlbackup.net to back up MySQL database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.