|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
为了在某种程序上弥补这一缺陷,许多SQL命令都有一个DELAY_KEY_WRITE项。这个选项的作用是暂时制止MySQL在该命令每插入一条新记录和每修改一条现有之后立刻对索引进行刷新,对索引的刷新将等到全部记录插入/修改完毕之后再进行。server|备份|数据|数据库办法一(不利用SQLDMO):
///
///备份办法
///
SqlConnectionconn=newSqlConnection("Server=.;Database=master;UserID=sa;Password=sa;");
SqlCommandcmdBK=newSqlCommand();
cmdBK.CommandType=CommandType.Text;
cmdBK.Connection=conn;
cmdBK.CommandText=@"backupdatabasetesttodisk=C:awithinit";
try
{
conn.Open();
cmdBK.ExecuteNonQuery();
MessageBox.Show("Backupsuccessed.");
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
///
///复原办法
///
SqlConnectionconn=newSqlConnection("Server=.;Database=master;UserID=sa;Password=sa;Trusted_Connection=False");
conn.Open();
//KILLDataBaseProcess
SqlCommandcmd=newSqlCommand("SELECTspidFROMsysprocesses,sysdatabasesWHEREsysprocesses.dbid=sysdatabases.dbidANDsysdatabases.Name=test",conn);
SqlDataReaderdr;
dr=cmd.ExecuteReader();
ArrayListlist=newArrayList();
while(dr.Read())
{
list.Add(dr.GetInt16(0));
}
dr.Close();
for(inti=0;i<list.Count;i++)
{
cmd=newSqlCommand(string.Format("KILL{0}",list),conn);
cmd.ExecuteNonQuery();
}
SqlCommandcmdRT=newSqlCommand();
cmdRT.CommandType=CommandType.Text;
cmdRT.Connection=conn;
cmdRT.CommandText=@"restoredatabasetestfromdisk=C:a";
try
{
cmdRT.ExecuteNonQuery();
MessageBox.Show("Restoresuccessed.");
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
办法二(利用SQLDMO):
///
///备份办法
///
SQLDMO.Backupbackup=newSQLDMO.BackupClass();
SQLDMO.SQLServerserver=newSQLDMO.SQLServerClass();
//显现进度条
SQLDMO.BackupSink_PercentCompleteEventHandlerprogress=newSQLDMO.BackupSink_PercentCompleteEventHandler(Step);
backup.PercentComplete+=progress;
try
{
server.LoginSecure=false;
server.Connect(".","sa","sa");
backup.Action=SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
backup.Database="test";
backup.Files=@"D: estmyProgackupTest";
backup.BackupSetName="test";
backup.BackupSetDescription="Backupthedatabaseoftest";
backup.Initialize=true;
backup.SQLBackup(server);
MessageBox.Show("Backupsuccessed.");
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
}
finally
{
server.DisConnect();
}
this.pbDB.Value=0;
///
///复原办法
///
SQLDMO.Restorerestore=newSQLDMO.RestoreClass();
SQLDMO.SQLServerserver=newSQLDMO.SQLServerClass();
//显现进度条
SQLDMO.RestoreSink_PercentCompleteEventHandlerprogress=newSQLDMO.RestoreSink_PercentCompleteEventHandler(Step);
restore.PercentComplete+=progress;
//KILLDataBaseProcess
SqlConnectionconn=newSqlConnection("Server=.;Database=master;UserID=sa;Password=sa;Trusted_Connection=False");
conn.Open();
SqlCommandcmd=newSqlCommand("SELECTspidFROMsysprocesses,sysdatabasesWHEREsysprocesses.dbid=sysdatabases.dbidANDsysdatabases.Name=test",conn);
SqlDataReaderdr;
dr=cmd.ExecuteReader();
ArrayListlist=newArrayList();
while(dr.Read())
{
list.Add(dr.GetInt16(0));
}
dr.Close();
for(inti=0;i<list.Count;i++)
{
cmd=newSqlCommand(string.Format("KILL{0}",list),conn);
cmd.ExecuteNonQuery();
}
conn.Close();
try
{
server.LoginSecure=false;
server.Connect(".","sa","sa");
restore.Action=SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
restore.Database="test";
restore.Files=@"D: estmyProgackupTest";
restore.FileNumber=1;
restore.ReplaceDatabase=true;
restore.SQLRestore(server);
MessageBox.Show("Restoresuccessed.");
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
}
finally
{
server.DisConnect();
}
this.pbDB.Value=0;
导致了一个使用几乎和mSQL一样的API接口的用于他们的数据库的新的SQL接口的产生,这样,这个API被设计成允许为用于mSQL而写的第三方代码更容易移植到MySQL。 |
|