This topic is locked
[SOLVED]

  Change or add to a Database Primary Key Violation Error

5/6/2010 2:34:47 PM
PHPRunner General questions
J
jackieh author

A user gets the error message below when trying to Add Record and the record violates the database table's primary key.

How can I add to this message or change the error message to give instructions on how to correct it?

I would like the user to get the instruction that they cannot add a record that has the same date or time.

------------------------------------------
<<< Record was NOT added >>>
[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PK_tbl_NPAU_log_2'. Cannot insert duplicate key in object 'dbo.tbl_NPAU_log'.
-----------------------------
Thank you very much.

E
electromotive 5/6/2010



A user gets the error message below when trying to Add Record and the record violates the database table's primary key.

How can I add to this message or change the error message to give instructions on how to correct it?

I would like the user to get the instruction that they cannot add a record that has the same date or time.

------------------------------------------
<<< Record was NOT added >>>
[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PK_tbl_NPAU_log_2'. Cannot insert duplicate key in object 'dbo.tbl_NPAU_log'.
-----------------------------
Thank you very much.



No worries mate. Create a "before record added" event with a few lines of php/sql code to first check the key value you wanna use, and if it already exists then display a user friendly message.

J
jackieh author 5/6/2010

Thanks electro rick!
Sergey, is there another way to change this message or should I do what Electro Rick suggests.

Sergey Kornilov admin 5/7/2010

This error message is coming directly from the database which means you cannot change it.
What electro rick suggests is a solid idea.

J
jackieh author 5/7/2010



This error message is coming directly from the database which means you cannot change it.
What electro rick suggests is a solid idea.


Thank you both very much.