sql server备份
我一段恢复程序,在执行恢复语句是经常出错,但有时也能成功,请问是什么原因(数据库备份没有问题)
//ls_server 服务器名称 ls_path 路径
string ls_server,ls_use,ls_path
DISCONNECT using sqlca;
SQLCA.DBMS = "MSS Microsoft SQL Server 6.x"
SQLCA.Database = "master"
SQLCA.LogPass = ""
SQLCA.ServerName = ls_server
SQLCA.LogId = sa
SQLCA.AutoCommit = TRUE
SQLCA.DBParm = ""
CONNECT using sqlca ;
ls_use = "exec sp_dropdevice 'jaguar'"
EXECUTE IMMEDIATE : ls_use ;
ls_use = "EXEC sp_addumpdevice 'disk' "+" , 'jaguar' "+","+" '"+path+"'"
EXECUTE IMMEDIATE : ls_use ;
ls_use = "RESTORE DATABASE " + dbase + " FROM DISK = "+" '"+path+"' "
EXECUTE IMMEDIATE : ls_use ;
ls_use = "EXEC sp_dropdevice 'jaguar'"
EXECUTE IMMEDIATE : ls_use ;
问题点数:1、回复次数:1Top
1 楼powerbu(变)回复于 2002-03-28 11:41:23 得分 1
l_response=messagebox("","是否真的要恢复数据库?",question!,yesno!)
if l_response= 1 then
str_databasename=sqlca.database
messagebox("","正在恢复数据库。。。。。。")
Commit using sqlca ;
DISCONNECT ;
transaction ts_temp
ts_temp=create transaction
ts_temp.DBMS = "MSS Microsoft SQL Server 6.x"
ts_temp.Database = "MASTER"
ts_temp.LogPass = "991225"
ts_temp.ServerName ="dbbuilder"
ts_temp.LogId = "sa"
ts_temp.AutoCommit = TRUE
ts_temp.DBParm = ""
CONNECT using ts_temp;
str_sqlexecute="exec sp_dboption HIS,'dbo',true"
EXECUTE IMMEDIATE :str_sqlexecute using ts_temp;
if ts_temp.sqlcode< > 0 then
messagebox("",ts_temp.sqlerrtext)
end if
str_sqlexecute ="EXEC sp_addumpdevice 'disk' , 'back',~'d:\back.bak~'"
EXECUTE IMMEDIATE : str_sqlexecute using ts_temp;
if ts_temp.sqlcode< > 0 then
messagebox("",ts_temp.sqlerrtext)
end if
str_sqlexecute ="RESTORE DATABASE HIS from disk=~"d:\back.bak~""
EXECUTE IMMEDIATE : str_sqlexecute using ts_temp;
if ts_temp.sqlcode< > 0 then
messagebox("",ts_temp.sqlerrtext)
end if
str_sqlexecute ="EXEC sp_dropdevice back"
EXECUTE IMMEDIATE : str_sqlexecute using ts_temp;
if ts_temp.sqlcode = 0 then
this.text="恢复完毕!"
str_sqlexecute = "exec sp_dboption HIS,'dbo',false"
EXECUTE IMMEDIATE :str_sqlexecute using ts_temp;
destroy ts_temp
else
messagebox("",ts_temp.sqlerrtext)
end if
end if
connect using sqlca;
这是我以前写的一个恢复程序,好象没出过问题。Top
2 楼powerbu(变)回复于 2002-03-28 11:42:48 得分 0
l_response=messagebox("","是否真的要恢复数据库?",question!,yesno!)
if l_response= 1 then
str_databasename=sqlca.database
messagebox("","正在恢复数据库。。。。。。")
Commit using sqlca ;
DISCONNECT ;
transaction ts_temp
ts_temp=create transaction
ts_temp.DBMS = "MSS Microsoft SQL Server 6.x"
ts_temp.Database = "MASTER"
ts_temp.LogPass = "991225"
ts_temp.ServerName ="dbbuilder"
ts_temp.LogId = "sa"
ts_temp.AutoCommit = TRUE
ts_temp.DBParm = ""
CONNECT using ts_temp;
str_sqlexecute="exec sp_dboption HIS,'dbo',true"
EXECUTE IMMEDIATE :str_sqlexecute using ts_temp;
if ts_temp.sqlcode< > 0 then
messagebox("",ts_temp.sqlerrtext)
end if
str_sqlexecute ="EXEC sp_addumpdevice 'disk' , 'back',~'d:\back.bak~'"
EXECUTE IMMEDIATE : str_sqlexecute using ts_temp;
if ts_temp.sqlcode< > 0 then
messagebox("",ts_temp.sqlerrtext)
end if
str_sqlexecute ="RESTORE DATABASE HIS from disk=~"d:\back.bak~""
EXECUTE IMMEDIATE : str_sqlexecute using ts_temp;
if ts_temp.sqlcode< > 0 then
messagebox("",ts_temp.sqlerrtext)
end if
str_sqlexecute ="EXEC sp_dropdevice back"
EXECUTE IMMEDIATE : str_sqlexecute using ts_temp;
if ts_temp.sqlcode = 0 then
this.text="恢复完毕!"
str_sqlexecute = "exec sp_dboption HIS,'dbo',false"
EXECUTE IMMEDIATE :str_sqlexecute using ts_temp;
destroy ts_temp
else
messagebox("",ts_temp.sqlerrtext)
end if
end if
connect using sqlca;
这是我以前写的一个恢复程序,好象没出过问题。Top




