如何让PB判断是否断开数据库?(后台数据库为Oracle 10g)

rsy123 2008-01-09 11:40:57
环境:PowerBuilder10.0和Oracle 10g数据库
要求:由于我的程序需要长期运行,但是有时数据库会断开我的连接。因此我需要程序能够自动判断数据库是否断开连接,再自动连接。我是这么做的,在窗体的timing控件里加入以下语句,并设置时间间隔为1秒

try
select tel_8001 into :state from scott.TELE_UPDATE; //做select操作
finally
if re_connect(1)=1 then //re_connect是重新连接函数
sys_log("已经完成与数据库重新连接") //sys_log是自己编的打印信息函数
commit;
return

end if

end try

但是再实际运行中,我却发现PB的程序在不断的重新连接数据库(每隔1秒),请问如何做才能够准确判断数据库的连接状态,谢谢?

顺便附上连接的脚本(采用Oracle9i专用接口的连接方式 )
disconnect;
string ls_msg
SQLCA.DBMS = "O90 Oracle9i (9.0.1)"
SQLCA.LogPass = "tiger"
SQLCA.ServerName = "hangang"
SQLCA.LogId = "sys"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectAs='SYSDBA'"
connect;
IF SQLca.sqlcode=-1 then
ls_msg='启动数据库失败...'+sqlca.sqlerrtext
messagebox("错误",ls_msg)
else
....
end if
...全文
461 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun1976 2008-01-10
  • 打赏
  • 举报
回复
if sqlca.dbcode>0 then return

string ls_msg
SQLCA.DBMS = "O90 Oracle9i (9.0.1)"
SQLCA.LogPass = "tiger"
SQLCA.ServerName = "hangang"
SQLCA.LogId = "sys"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectAs='SYSDBA'"
connect;
IF SQLca.sqlcode=-1 then
ls_msg='启动数据库失败...'+sqlca.sqlerrtext
messagebox("错误",ls_msg)
else
....
end if
jlwei888 2008-01-10
  • 打赏
  • 举报
回复
你 disconnect;了吗?
rsy123 2008-01-10
  • 打赏
  • 举报
回复
让我试试
kenshu 2008-01-10
  • 打赏
  • 举报
回复
long i
select 1 into :i from dual;
if sqlca.sqlcode = 0 then
return;
else
connect using sqlca;
end if

1,108

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧