I am aware of:
SELECT @@ERROR
but it will give me only an ERROR CODE (a number) and I need a full text message like:
Cannot insert duplicate key row in object 'dbo.TABLE_NAME' with unique index 'IX_ID_unique'.
The statement has been terminated.
How can I do that in MS Sql Server 2005 ?
EDIT: I need to acquire this error message on Linux and Windows platforms.
When called in a CATCH block, ERROR_MESSAGE returns the complete text of the error message that caused the CATCH block to run. The text includes the values supplied for any substitutable parameters - for example, lengths, object names, or times. ERROR_MESSAGE returns NULL when called outside the scope of a CATCH block.
SQL Server doesn't store, and thus doesn't know, the "last accessed date" for each db. After SQL starts, when any index is accessed, an entry for that db and index is to added to the sys. dm_db_index_usage_stats view. When SQL shuts down, all that info is lost.
What about ERROR_MESSAGE
?
See also : Retrieving Error Information in Transact-SQL
And, from PHP (as your question is tagged php
), take a look at :
mssql_get_last_message
PDO::errorInfo
Depending on the API you're using to access your MS SQL Server database, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With