Page 1 of 1
exception handeling connecting tot mysql server/database
Posted: Mon 22 Feb 2010 21:44
by alpha
Hi All,
probably a trivial question, but how do I handel errors occuring when for example my sql server is down, or there is some other problem conecting to the database?
try .. except
Thnks
Simon
Posted: Tue 23 Feb 2010 10:50
by Dimon
You can process an exception on connecting like this:
Code: Select all
try
MyConnection.Connect;
except
on e: EDAError do
if e.Message = '' then
// processing of message
end;
Posted: Tue 23 Feb 2010 11:15
by alpha
Tnks for the reply.
Unfortunately your solution does not work.
I still get the eroor message:
".. raised exception class SocketException..." when de mysql server is not available
Posted: Tue 23 Feb 2010 14:19
by Dimon
Then you can use the SocketException class, or the Exception class, like this:
Code: Select all
try
MyConnection.Connect;
except
on e: EDAError do
// processing of message
on e: SocketException do
// processing of message
on e: Exception do
// processing of message
end;
Posted: Tue 23 Feb 2010 14:19
by Dimon
Please, specify what error does arise?
Posted: Tue 23 Feb 2010 19:55
by alpha
When de server is not available, and thus the mysql database not reachable the statement myconnection.connect generates the error:
.. raised exception class SocketException...
The advice given above generates a compilation error in the statement:
on e: SocketException do
because SocketException is not known.
Probably I must ad a unit to the uses clause? Which? I could not find it in the help
Posted: Wed 24 Feb 2010 10:01
by Dimon
If you use the SecureBridge components, you should inlude the ScSSHUtil unit to the uses clause, if not - add the CRVioTcp unit.