Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get last full MS SQL Server error message?

Tags:

php

sql-server

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.

like image 817
Dawid Ohia Avatar asked May 02 '10 11:05

Dawid Ohia


People also ask

How do I get SQL Server error messages?

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.

How do I find the last usage of a SQL Server database?

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.


1 Answers

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.

like image 197
Pascal MARTIN Avatar answered Oct 23 '22 05:10

Pascal MARTIN