请问怎样在程序中实现数据库的恢复(已有备份文件)(在线......)

learn03 2003-05-11 10:52:45
同上(解决立即给分)
...全文
8 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
learn03 2003-05-15
这个问题发了四天了

为什么没人答?

难道真的很难吗?

还是分不够?

问题解决可以在给!

回复
bomber2001 2003-05-15
恢复代码
(转载)



int li_index,li_count,li_ret
string ls_syntax,ls_errors,ls_colname,ls_modstring,ls_sql
string ls_list[]

st_1.text=" 正在恢复....."

ls_syntax="select * from jdrm_2"
dw_1.create(sqlca.syntaxfromsql(ls_syntax,"style(type=grid)",ls_errors))
if len(ls_errors) > 0 then
messagebox("","恢复借档人资料库时发生错误,停止恢复!",stopsign!)
return
end if
dw_1.settransobject(sqlca)
ls_syntax="select * from jdrm_2"
if dw_1.modify("datawindow.table.select=~'ls_syntax~'")<>"" then
messagebox("","数据库表出错,无法恢复!",stopsign!)
return
end if
if dw_1.modify("datawindow.table.updatetable='jdrm_2'")<>"" then
messagebox("wrong!","表不可修改!")
return
end if
do while li_count > 0
ls_colname= ls_list[li_count]
ls_modstring=ls_colname+".update" + "=" + "yes"
if dw_1.modify(ls_modstring) <> "" then
messagebox("错误","表不可修改!")
return
else
li_count --
end if
loop
if filelength("c:\temp\借档人资料库.dbf")=-1 then
messagebox("","没有借档人资料库的备份数据",stopsign!)
return
end if
ls_sql="delete from jdrm_2"
execute immediate :ls_sql;
if sqlca.sqlcode<>0 then
messagebox("失败","清表失败,停止恢复!",stopsign!)
return
end if
do while dw_1.rowcount() > 0
dw_1.deleterow(0)
loop
li_ret=dw_1.importfile("c:\temp\借档人资料库.dbf")
if li_ret < -2 then
messagebox("错误","恢复借档人资料库时出现错误,停止恢复!",stopsign!)
return
end if
if dw_1.update()=1 then
commit;
else
rollback;
end if

st_1.text="恢复完毕!"

回复
bomber2001 2003-05-15
备份代码
(转载)


int li_index,li_total,li_ret
string ls_syntax,ls_errors,ls_directory

st_1.text="正在备份........"
//ls_directory=sle_1.text
ls_syntax="select * from jdjm_table_1"
dw_1.create(sqlca.syntaxfromsql(ls_syntax,"style(type=grid)",ls_errors))
if len(ls_errors) > 0 then
messagebox("","备份借档案卷数据库时发生错误,停止备份!",stopsign!)
return
end if
dw_1.settransobject(sqlca)
dw_1.retrieve()
li_ret=dw_1.saveas( "c:\temp\借档案卷资料库.dbf",dbase3!,true)
if li_ret=-1 then messagebox("备份失败","备份失败!")

st_1.text="备份完毕!"
回复
kkk3k 2003-05-15
twb88 :
能给出备份数据库文件的代码吗?谢谢!
回复
twb88 2003-05-11
自已看吧
给分吧
回复
twb88 2003-05-11
String ls_path,ls_use

ls_path = sle_repath.text
IF ls_path = "" THEN
Messagebox('系统提示',"请先选择要恢复的数据文件! ")
sle_repath.SetFocus()
RETURN
END IF
COMMIT USING SQLCA ;
SetPointer(HourGlass!)//---开始恢复
//恢复的原因,连接到master数据库
DISCONNECT USING SQLCA ;
Transaction SQLCA_MASTER
SQLCA_MASTER = CREATE Transaction
SQLCA_MASTER.DBMS = "MSS Microsoft SQL Server 6.x"
SQLCA_MASTER.DataBase = "master"
SQLCA_MASTER.LogId = "sa"
SQLCA_MASTER.AutoCommit = TRUE
SQLCA_MASTER.DBParm = ""
CONNECT USING SQLCA_MASTER ;

This.Enabled = FALSE
cb_backup.Enabled = FALSE

ls_use = "EXEC sp_addumpdevice 'disk' "+" , 'coolnan' "+","+" '"+ls_path+"' "
EXECUTE IMMEDIATE : ls_use USING SQLCA_MASTER;

ls_use = "RESTORE DATABASE picture FROM coolnan"//DISK = "+" '"+ls_path+"' "
EXECUTE IMMEDIATE : ls_use USING SQLCA_MASTER;

IF SQLCA_MASTER.SQLCODE = -1 THEN
Messagebox("系统信息","警告:数据库恢复失败!~r~n~n请确认路径以及所选文件正确与否!",Stopsign!)
This.Enabled = TRUE
cb_backup.Enabled = TRUE
SQLCA.SQLCODE = 0
SQLCA.SQLDBCODE = 0
ls_use = "EXEC sp_dropdevice 'coolnan'"
EXECUTE IMMEDIATE : ls_use USING SQLCA_MASTER;
RETURN
END IF

ls_use = "EXEC sp_dropdevice 'coolnan'"
EXECUTE IMMEDIATE : ls_use USING SQLCA_MASTER;

IF SQLCA_MASTER.SQLCODE = 0 THEN
Messagebox("系统信息","数据库恢复完成!")
This.Enabled = TRUE
cb_backup.Enabled = TRUE
RETURN
ELSE
Messagebox('系统信息','数据库备份操作未进行!',Stopsign!)
RETURN
END IF
DISCONNECT USING SQLCA_MASTER ;
CONNECT USING SQLCA ;
SetPointer(HourGlass!)
回复
xirumin 2003-05-11
首先要断开与你的数据库的连接,而连到master数据库上,接下来就省事了。与备份差不多
回复
twb88 2003-05-11
用execute immediate 执行动态语句,SQL就一样了
呵呵,不知道写得对不对
回复
learn03 2003-05-11
应该改些什么呢?
device名已经改过了,还是不好用
再有sqlca_master需不需要改呢?
请指点一下
谢谢!
回复
twb88 2003-05-11
你改一改呀
不能照抄
回复
learn03 2003-05-11
谢谢twb88!
运行之后,弹出错误信息,如下:
Cannot open backup device 'coolnan'.Device error or device off-line.
See the SQL Server error log for more details.
请问这是什么原因?
回复
相关推荐
发帖
PowerBuilder
创建于2007-09-28

891

社区成员

PowerBuilder 相关问题讨论
申请成为版主
帖子事件
创建了帖子
2003-05-11 10:52
社区公告
暂无公告