Board index » delphi » The best way to handle databaseErrors???

The best way to handle databaseErrors???

Hello, I really get a headache whats the best way to handle Errors
in my Database [D4]...?

I have a Table with Customers, every Customer has its unique number,
It is not allowed to use the same number twice.
But what happens if you try to do this either?

Do you check, if there is already a Customer with this number, maybe
in the BeforePost Event?
Or will you handle a EDBEngineError like Key Violation? Or what would
you
do?

I am really stuck with this problem and would like to share your
experiences.

Thanks in advance
Dirk

 

Re:The best way to handle databaseErrors???


Quote
Dirk Siepe wrote:

> Hello, I really get a headache whats the best way to handle Errors
> in my Database [D4]...?

> I have a Table with Customers, every Customer has its unique number,
> It is not allowed to use the same number twice.
> But what happens if you try to do this either?

> Do you check, if there is already a Customer with this number, maybe
> in the BeforePost Event?
> Or will you handle a EDBEngineError like Key Violation? Or what would
> you
> do?

> I am really stuck with this problem and would like to share your
> experiences.

> Thanks in advance
> Dirk

Dirk,

Leave it to the database to catch the duplicate. If you do not like the
way Delphi reacts to the error, catch it ("try...except" around the
post). Minimize the risk by having your software assign the numbers.
Autoincrement fields are only reliable in the simplest of cases. The
best way is to have a table with a small amount of free numbers that you
delete once you start using one.

There are many other worthwile schemes, check the newsgroup; this is a
hot item.

HTH

Menno

Re:The best way to handle databaseErrors???


In article <37446560.9B98...@uni-bonn.de>, Dirk Siepe <uzs74h@uni-
bonn.de> writes

Quote
>Hello, I really get a headache whats the best way to handle Errors
>in my Database [D4]...?

>I have a Table with Customers, every Customer has its unique number,
>It is not allowed to use the same number twice.
>But what happens if you try to do this either?

Depends what kind of database you are using.  You might be able to set
the Customer Key as the main (unique) index.
--
Pete Clark

Replies to pete at elmsoft demon co uk

Other Threads