procedure TDataModule2.DataModuleCreate(Sender: TObject); var S_Temp : String ;begin DataConnetions := '' ; Database1.Params.Add('PASSWORD=lyylscc'); // Database1.Params.Add('PASSWORD= '); try Database1.Connected := True; DataConnetions := 'OK' ; except on E: Exception do begin S_Temp := E.Message ; DataConnetions := 'Failed' ; if pos('登录失败',S_Temp) > 0 then ExceptionType := '口令有误' else ExceptionType := '无法联接服务器'; end ; end ;end;
try if not DataBase.connected then DataBase.connected := true; except Common.ShowError('连接数据库时错误!'); Application.ShowMainForm := False; Application.Terminate; Exit; end;
请大伙看清问题呀!我说了: 如何判断数据库连接是否成功,我用 DM.ADOConnection.Connected 来判断但是不行呀! 我的代码是: if DM.ADOConnection.Connected then begin showmessage('ok'); -------------------->显示OK DM.ADOQuery1.close; DM.ADOQuery1.SQL.clear; DM.ADOQuery1.SQL.Add('select * from InTable'); ---------->SQL语句绝对没错 DM.ADOQuery1.open; -------------------->出错!!! 5555555!为什么呀! end else begin showmessage('err'); end;
if DM.ADOConnection.Connected then begin showmessage('ok');-------------------->显示OK ADOQuery1.Connection:=DM.Adoconnection;//试试 DM.ADOQuery1.close; DM.ADOQuery1.SQL.clear; DM.ADOQuery1.SQL.Add('select * from InTable'); ---------->SQL语句绝对没错 DM.ADOQuery1.open; -------------------->出错!!! 5555555!为什么呀! end else begin showmessage('err'); end;
你用ADO就有这毛病,请在DM.ADOQuery1.SQL.Add('select * from InTable'); 后加上while not ADOQuery1.eof then ......。就可以了。
begin
MessageDlg('Connected. ', mtInformation, [mbOK], 0);
end;
showmessage('ok');
adoconnection1.Connected:=true;
showmessage('成功');
except
showmessage('连接失败');
end;
adoconnection1.Connected:=true;
showmessage('成功');
except
showmessage('连接失败');
end;
var S_Temp : String ;begin
DataConnetions := '' ;
Database1.Params.Add('PASSWORD=lyylscc');
// Database1.Params.Add('PASSWORD= ');
try
Database1.Connected := True;
DataConnetions := 'OK' ;
except
on E: Exception do
begin
S_Temp := E.Message ;
DataConnetions := 'Failed' ;
if pos('登录失败',S_Temp) > 0 then
ExceptionType := '口令有误'
else
ExceptionType := '无法联接服务器';
end ;
end ;end;
if not DataBase.connected then
DataBase.connected := true;
except
Common.ShowError('连接数据库时错误!');
Application.ShowMainForm := False;
Application.Terminate;
Exit;
end;
我的代码是:
if DM.ADOConnection.Connected then
begin
showmessage('ok'); -------------------->显示OK
DM.ADOQuery1.close;
DM.ADOQuery1.SQL.clear;
DM.ADOQuery1.SQL.Add('select * from InTable'); ---------->SQL语句绝对没错
DM.ADOQuery1.open; -------------------->出错!!! 5555555!为什么呀!
end
else
begin
showmessage('err');
end;
if DM.ADOConnection.Connected then
begin
showmessage('ok');-------------------->显示OK
ADOQuery1.Connection:=DM.Adoconnection;//试试
DM.ADOQuery1.close;
DM.ADOQuery1.SQL.clear;
DM.ADOQuery1.SQL.Add('select * from InTable'); ---------->SQL语句绝对没错
DM.ADOQuery1.open; -------------------->出错!!! 5555555!为什么呀!
end
else
begin
showmessage('err');
end;