views:

139

answers:

0

Hi,

Does anyone know of a way to capture an error message returned from a linked server?

As an example, if i run the following command in SQL Server management studio:

BEGIN TRY
 exec ('select * from xxx') at my_linked_server
END TRY

BEGIN CATCH
  print  'ErrorNumber...'+  CAST(ERROR_NUMBER() as varchar)
  print  'ErrorSeverity...'+  CAST(ERROR_SEVERITY() as varchar)
  print  'ErrorState...'+  CAST(ERROR_STATE() as varchar)
  print  'ErrorProcedure...'+ IsNull(ERROR_PROCEDURE(),'')
  print  'ErrorLine...'+  CAST(ERROR_LINE() as varchar)
  print  'ErrorMessage...'+  IsNull(ERROR_MESSAGE(),'')
END CATCH

I get the following results:

OLE DB provider "MSDASQL" for linked server "my_linked_server" returned message "[Informix][Informix ODBC Driver][Informix]The specified table (xxx) is not in the database.". ErrorNumber...7215 ErrorSeverity...17 ErrorState...1 ErrorProcedure... ErrorLine...3 ErrorMessage...Could not execute statement on remote server 'my_linked_server'.

I wondered if Sql Server stores the OLE DB provider error as it would be useful to capture this info for debugging.

Any help much appreciated. :)