麻烦看一下,到底为什么一直无法再连上。
我在W_MAIN做了一个TIMER(事件)每隔60秒检查一次连接是否断开,如果是断开则:
if sqlca.sqlcode =-1 then
disconnect ;
timer(0)
this.visible = false
openwithparm(w_sql_err,sqlca.sqlerrtext)
return
end if
//以上代码可以理解
sqlcode = -1 时断开时,停止了TIMER事件,把w_main隐起来,然后打开W_sql_err
=============================================
w_sql_err 的open事件
==========================================
string ls_sql_err
ll_once=0
ls_sql_err= message.stringParm
mle_1.text=ls_sql_err +' 无法连接服务器!系统将会在60秒后重新登陆!'
integer li_height, li_width
Environment env
GetEnvironment (env)
li_height = env.ScreenHeight
li_width = env.ScreenWidth
//this.height=PixelsToUnits(li_height,YPixelsToUnits!) - 120
this.X = PixelsToUnits(li_width,XPixelsToUnits!) - this.width
this.y=PixelsToUnits(li_height,YPixelsToUnits!) - this.height -150
timer(5)
======================
w_sql_err 的timer()事件
ll_once++
st_1.text ="第" + string(ll_once) +'次尝试登陆失败!'
disconnect;
if uf_connect(sqlca) <> -1 then
time(0)
close(w_main)
open(w_main)
close(this)
else
mle_1.text = sqlca.sqlerrtext + "错误码:" + string(sqlca.sqlcode)
end if
========================================================================
以上代码我的执行实验是
先把程序打开,一切正常,然后我手动把SQL2000的服务停止.这时W_SQL_ERR正常打开,然后我再手动启动SQL2000的服务,可是程序已经无法再联接上SQL2000了。
=======================================================================
请问是什么原因呢?
[解决办法]
你的程序是通过sqlca.sqlcode=-1来判断的,而这个sqlcode是要与数据库有交互时才会改变值的,所以正常情况下,你的重连代码是不可能运行到的;
如果有其他地方调用SQL导致为-1,也会有假死机现象,在这过程中timer事件是不会被执行的,
理论上你的代码在数据库交互有错误时还是会执行的,只是会等待很久,你再试试看,
不过还有个问题,sqlca.sqlcode=-1不一定是数据库断开了,还有其他可能~~
[解决办法]