winform程序如何备份mysql数据库。 用的ADO.Net driver for MySQLMySql.Data.dll这个dll想弄一个按钮,可以备份数据库,请问应该怎么做。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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()); }你应该可以看懂吧?在按钮事件里做就可以了 /// <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; } 在一论坛上看到的问题!!! C#读取16进制数据流问题 请教事件线程问题 没有写过C/S 程序,有一个幼稚问题问一下! 数据库中的数据纪录丢失 100分,求ScheduleMIS框架!!!!!!! c#中,如何利用FileStream修改一個只讀文件的內容? Administrator帐户密码被改问题,望高手进…… C#可不可以创建可更新记录集 关于C#代码到窗体的问题 问一些关于路由与NAT的问题 关于WinFrom引用DLL
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());
}
你应该可以看懂吧?在按钮事件里做就可以了
/// <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;
}