当网络断开进行连接时,不能执行except语句,而是系统报错,为何?
try
ADOConnection.Connected:=True;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('Select * from xtgl_czy where loginid=');
ADOQuery.SQL.Add(''''+edLogin.Text+'''');
ADOQuery.SQL.Add(' and password=');
ADOQuery.SQL.Add(''''+edPsw.Text+'''');
ADOQuery.Open; if ADOQuery.RecordCount=0 then
Application.MessageBox('用户名或密码错!','错误',MB_OK+MB_ICONWARNING)
else
begin
Self.Hide;
ADOConnection.Connected:=False;
ADOQuery.Close;
DataChkForm.Show;
end;
except
Application.MessageBox('无法与服务器连接!','错误',MB_OK+MB_ICONWARNING);
end;
其中CommandTimeout:=30,ConnectionTimeout:=30
try
ADOConnection.Connected:=True;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('Select * from xtgl_czy where loginid=');
ADOQuery.SQL.Add(''''+edLogin.Text+'''');
ADOQuery.SQL.Add(' and password=');
ADOQuery.SQL.Add(''''+edPsw.Text+'''');
ADOQuery.Open; if ADOQuery.RecordCount=0 then
Application.MessageBox('用户名或密码错!','错误',MB_OK+MB_ICONWARNING)
else
begin
Self.Hide;
ADOConnection.Connected:=False;
ADOQuery.Close;
DataChkForm.Show;
end;
except
Application.MessageBox('无法与服务器连接!','错误',MB_OK+MB_ICONWARNING);
end;
其中CommandTimeout:=30,ConnectionTimeout:=30
在你的文件目录下运行看看
except
on e:exception do
showmessage(e.classname + e.message)
end;
试试。