Board index » delphi » Wich is the best way to handling errors with MS-SQL SERVER 6.5

Wich is the best way to handling errors with MS-SQL SERVER 6.5

Hi !, i'm using SQL server 6.5 , but i don't know how to handling errors
like Primary key or null value, wich is the best way two do that ?

Thanks

 

Re:Wich is the best way to handling errors with MS-SQL SERVER 6.5


Damian:
IMHO, you shouldn't worry too much about these errors. First of all, NOT
NULL requirements are automatically handle by the VCL. Possibly, you want to
translate the message ("Field xxx must have a value") to your language. The
best way to do it is by translating the VCL resources, not adding a single
line of code to your program. I have seen too many programs doing this
translation the hard way; as a consequence, they become a real nightmare to
understand them. (Remember, however, that null values and empty strings are
different; maybe you should better add to your data dictionary constraints
like column <> '')
Another common "mistake": I've seen people who validates the uniqueness of a
primary key with OnValidate, trying to detect the key violation as soon as
the user types the new key. IMHO, again, this is wasted time. This
validation cannot ensure, in a concurrent environment, that this key will
still be valid when the user saves the current record. Of course, there's
some merit with early "validation", but I believe it's not worthwhile.
However, you'll need to contextualize the "Key violation" error message.
Translating it  is not enough, most of the times. Normally, I use
OnPostError, OnEditError & OnDeleteError to intercept EDBEngineError
exceptions, and bringing them into context. By instance:

  "Key violation"  --> "Duplicated customer ID or name"
  "Master record missing" --> "This purchase order has details"

If you need to know how to extract the numeric code given the exception
object, look at www.mar{*word*249}s.com/trick03.htm.

Ian

Re:Wich is the best way to handling errors with MS-SQL SERVER 6.5


Hello

I'm agree with you but you say

Quote
>Another common "mistake": I've seen people who validates the uniqueness of
a
>primary key with OnValidate, trying to detect the key violation as soon as
>the user types the new key. IMHO, again, this is wasted time. This
>validation cannot ensure, in a concurrent environment, that this key will
>still be valid when the user saves the current record. Of course, there's
>some merit with early "validation", but I believe it's not worthwhile.
>However, you'll need to contextualize the "Key violation" error message.

I want to ask you if this is correct

In table Before post:

StartTransaction
Search for the primary key
If it exist raise an exception

In table after post
Commit

Thanks

Re:Wich is the best way to handling errors with MS-SQL SERVER 6.5


Hi, Toni:

Quote
>In table Before post:

>StartTransaction
>Search for the primary key
>If it exist raise an exception

>In table after post
>Commit

This code is also open to problems, since there is a little margin of time
between the search instruction and the update or insert instruction. And, if
you define a primary key, this code is totally redundant. I can't see a
reason for not defining a primary key (specially in client/server
environments).
Ian

Other Threads