I have a table in my database which essentially serves as a logging destination. I use it with following code pattern in my SQL code:
BEGIN TRY
...
END TRY
BEGIN CATCH
INSERT INTO [dbo.errors] (...)
VALUES ( ERROR_PROCEDURE(), ERROR_NUMBER(), ERROR_MESSAGE(), ... )
END CATCH
To make long story short some of this code must be executing withing a transaction. I'm figuring out that nothing gets written into log, since transaction rollback will roll back the error log entries as well. Anything can be done about it?
EDIT: I do know how to get around by doing a rollback/commit before an INSERT to log. My question was, if there is a known way to insert data so that it is unaffected by a transaction in progress. For example: it could be done if I insert it using a separate connection. Only I wanted to find the way to do it inside single SQL statement
EDIT2: Clarification: this is about Microsoft SQL