//声明相应的变量
string ls_database,ls_pass,ls_date,ls_time
integer li_gs,li_gs_o
transaction login_trans
login_trans = creat transaction
IF MessageBox("提示信息","是否真的要进行数据备份操作?", &
Exclamation!,OKCancel!,2)<>1 then return
//连接MSDB数据库
login_trans.database = "msdb"
connect using login_trans;
if login_trans.sqlcode <> 0 then
messagebox("数据库错误信息",login_trans.sqlerrtext)
return
end if
//检测上次该执行体执行结果,用以区别本次执行状况
select max(instance_id) into :li_gs_o from sysjobhistory using login_trans;
if isnull(li_gs_o) then li_gs_o =0
login_trans.autocommit = true
ls_pass = login_trans.logpass
//运行系统存储过程SP_START_JOB,启动执行体
prepare sqlsa from "sp_start_job ?" using login_trans;
if login_trans.sqlcode <> 0 then
messagebox("数据库错误信息",login_trans.sqlerrtext)
login_trans.autocommit = false
disconnect using login_trans;
login_trans.database = ls_database
return
end if
EXECUTE sqlsa USING ‘XCCXXT BACKUP’;
//检测执行体启动是否正常
if login_trans.sqlcode <> 0 then
messagebox("数据库错误信息",login_trans.sqlerrtext)
login_trans.autocommit = false
disconnect using login_trans;
return
end if
//检测执行体执行的整个过程
DO
uf_sleep (1)
select max(instance_id) into :li_gs from sysjobhistory using login_trans;
if isnull(li_gs) then li_gs =0
LOOP WHILE li_gs<=li_gs_o+1
//运行系统存储过程SP_END_JOB,关闭执行体
prepare sqlsa from "sp_end_job ?" using login_trans;
if login_trans.sqlcode <> 0 then
messagebox("数据库错误信息",login_trans.sqlerrtext)
login_trans.autocommit = false
disconnect using login_trans;
login_trans.database = ls_database
return
end if
EXECUTE sqlsa USING ‘XCCXXT BACKUP’;
//返回执行结果
li_gs_o=li_gs - 1
select run_
----------------------------------------------
s,run_date,run_time into :li_gs,:ls_date,
:ls_time from sysjobhistory where instance_id =:li_gs_o using login_trans;
if li_gs = 1 then
st_3.text = left(ls_date,4)+'年'+mid(ls_date,5,2)+'月'
+right(ls_date,2)+'日'+' '+&
left(ls_time,2)+':'+mid(ls_time,3,2)+':'+right(ls_time,2)
messagebox('提示',"数据库备份操作成功!")
else
messagebox('提示',"数据库备份操作失败!")
end if
//断开与数据库MSDB的连接
login_trans.autocommit = false
disconnect using login_trans;
if login_trans.sqlcode <> 0 then
messagebox("数据库错误信息",login_trans.sqlerrtext)
end if |