Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi 7 & DbExpress Error handling

Status
Not open for further replies.

aquayle

Technical User
May 30, 2003
3
GB
Just beginning, so will post loads..
1st, if MySql isn't running, this code errors:-

procedure TfrmLogon.Button1Click(Sender: TObject);
var uname,pword :string;
ErrorCode :Integer;
begin
uname :=edit1.Text;
pword := password.text;
if not frmDBcontrols.SQLConnection1.Connected then
begin
showMessage('Database Not connected');
try
frmDBcontrols.SQLConnection1.Connected:=true;
//if ErrorCode <> 0 then // only 0 should be correct
// raise Exception.Create('Error: code = ' + IntToStr(ErrorCode))
except
on E: Exception do
showMessage('error');
end;
end;
end;

is there an elegant way to trap the error if MySql isn't running? (I know that errorcode isn't used in this example)

Ta - Andy
 
your try block is being called wether or not connected = true.

try
Code:
procedure TfrmLogon.Button1Click(Sender: TObject);
var
 uname,pword :string;
 ErrorCode :Integer;
begin
 uname :=edit1.Text;
 pword := password.text;
 if not frmDBcontrols.SQLConnection1.Connected then
  showMessage('Database Not connected')
 else
  try
   frmDBcontrols.SQLConnection1.Connected:=true;
  except
   on E: Exception do showMessage('error');
  end;
end;

Aaron Taylor
John Mutch Electronics
 
I don't think that will work either?

if not frmDBcontrols.SQLConnection1.Connected then
showMessage('Database Not connected')
else
try
frmDBcontrols.SQLConnection1.Connected:=true;


if the connection is not connected show the message "database not connected" else (meaning the connection is connected) try to connect?



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top