请问如何判断一个事务对象是否联接到数据库

dreamman 2002-02-20 09:12:37
定义了一个事务对象MYTRANS。在某个窗口脚本运行之前,我想判断以下现在的MYTRANS是否已经联接数据库,如果联接了,就不在Connect了;如果还没有联接,就Connect using MYTRANS。

请问,如果做判断呢?谢谢。
...全文
64 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
icewolf_li 2002-03-28
  • 打赏
  • 举报
回复
但是接下来:
DBHandle returns a valid handle only if you are connected to the database. It is not able to determine if the database connection does not exist or has been lost.

也就是说我在调用connect using sqlca;
以后数据库正常连接上了。之后如果数据库端主动断开了连接(或者网络断了),在这些情况下DBHandle()的返回值仍旧是合法的,他不能判断数据库连接是否真的存在。
那么要判断数据库连接是否真的可用该怎么判断呢?
zxthello 2002-02-20
  • 打赏
  • 举报
回复
同意晓夏和清平乐的,但是一般在connect using mytrans;后面应该用晓夏的就行了
nixinyi 2002-02-20
  • 打赏
  • 举报
回复
取sqlca.dbhandle()返回值

见PB help

Reports the handle for your DBMS.
Return value:
Long. Returns the handle for your DBMS. Transactionobject must exist, and the database must be connected. If transactionobject exists but the database is not connected, DBHandle returns 0. If transactionobject does not exist, an execution error occurs. If transactionobject is NULL, DBHandle returns NULL.

当数据库未联结时,返回值为0。
IT晓夏 2002-02-20
  • 打赏
  • 举报
回复
if MyTRANS.sqlcode <> 0 then
MessageBox ("Information", "error connect:"+MYTRANS.sqlerrtext)
end if

IT晓夏 2002-02-20
  • 打赏
  • 举报
回复
if MyTRANS.sqlcode <> 0 then
MessageBox ("Information", "error connect:"+sqlca.sqlerrtext)
end if

zqllyh 2002-02-20
  • 打赏
  • 举报
回复
if sqlca.sqlcode <> 0 then
MessageBox ("对不起! 不能连接到数据库", sqlca.sqlerrtext)
end if

400

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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