用的ADO.Net driver for MySQL
MySql.Data.dll这个dll想弄一个按钮,可以备份数据库,请问应该怎么做。

解决方案 »

  1.   

    string cmd2 = "/c \"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\MYSQLDUMP.exe\" -u root -psa mysql >g:\\mysql.sql";
                try
                {
                    DialogResult result = MessageBox.Show("您是否真的想覆盖以前的数据库吗?那么以前的数据库数据将丢失!!!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start("cmd", cmd2);
                        MessageBox.Show("数据库备份成功!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
    你应该可以看懂吧?在按钮事件里做就可以了
      

  2.   


    /// <summary>
            /// 利用DMO备份数据库
            /// </summary>
            /// <returns></returns>
            private bool BackupSql()
            {
                this.m_oBackup = new SQLDMO.Backup();
                SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
                try
                {
                    oSQLServer.LoginSecure = false;
                    oSQLServer.Connect(this.m_strSqlHost, this.m_strSqlSA, this.m_strSqlPW);
                    this.m_oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
                    this.m_oBackup.Database = this.m_strSqlName;
                    this.m_strBackupName = string.Format("{0}\\{1}-{2}.bak", this.m_strBackupPath, this.m_strSqlName, Utility.GetFormatDate(DateTime.Now));
                    File.Delete(this.m_strBackupName);
                    this.m_oBackup.Files = this.m_strBackupName;
                    this.m_oBackup.BackupSetName = this.m_strSqlName;
                    this.m_oBackup.BackupSetDescription = string.Format("数据库备份-{0}", DateTime.Now);
                    this.m_oBackup.Initialize = true;
                    this.m_oBackup.SQLBackup(oSQLServer);
                }
                catch (Exception me)
                {
                    ErrorLog.SaveLog(LogType.SQ, "备份数据库失败!" + me.Message, "0");
                    // Socket
                    this.SendNodifyMsg(new TcpMsg(LogType.SQ, TcpMsgState.False, "备份数据库失败!"));
                    return false;
                }
                finally
                {
                    oSQLServer.DisConnect();
                    this.m_oBackup = null;                ErrorLog.SaveLog(LogType.SQ, "备份数据库成功!", "0");
                    // Socket
                    this.SendNodifyMsg(new TcpMsg(LogType.SQ, TcpMsgState.True, "备份数据库成功!"));
                }
                return true;
            }