|
-
Mar 22nd, 2002, 04:35 AM
#1
Thread Starter
Fanatic Member
SQL Guru's
I am writing a stored procedure in SQL thats fires erros to the event log.
The problem is this. If I run this code
Code:
DECLARE @CurrentMessage varchar(8000)
SET @CurrentMessage = 'Testing wether this works'
Print @CurrentMessage
EXEC master..xp_logevent 12345678, @CurrentMessage, ERROR
You can try this yourself.
Now the problem is because i am running the SQL in a transaction, when I hit an error it rollsback (understandable)
BUT
It also rollsback the event log entry
To get round this I have entered the errors in a string and hold it until I rollback
I then write it to the event log
Now Then:
I use this to write the errors to a string
Code:
SET @CurrentMessage = 'Testing wether this works'
SET @CurrentMessage = @CurrentMessage + CHAR(13) + CHAR(10) + 'on another line '
Print @CurrentMessage
EXEC master..xp_logevent 12345678, @CurrentMessage, ERROR
If you run this in Query Analyzer it displays the message on 2 lines.
If you look in the event log though it only copies the first line
Any suggestions
Gary Lowe 
VB6 (Enterprise) SP5
ADO 2.6
SQL Server 7 SP3
OK I know my spelling and grammer is crap so don't quote me on it!
To err is human to take the P! is only natural !!
Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip

-
Mar 22nd, 2002, 06:13 AM
#2
Thread Starter
Fanatic Member
Gary Lowe 
VB6 (Enterprise) SP5
ADO 2.6
SQL Server 7 SP3
OK I know my spelling and grammer is crap so don't quote me on it!
To err is human to take the P! is only natural !!
Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip

-
Mar 22nd, 2002, 06:24 AM
#3
Does
The event log only stores up to the new line char (in the exec bit)..?
Any way of looping for each line and exporting to the event log ?
My only idea - dunno about Sql Server (yet)
Regards
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Mar 22nd, 2002, 06:26 AM
#4
Thread Starter
Fanatic Member
Ahh Haaa
You have to add the char's at the end of the last text
Code:
SET @CurrentMessage = 'Testing wether this works'
SET @CurrentMessage = @CurrentMessage + CHAR(13) + CHAR(10) + 'on another line ' + CHAR(13) + CHAR(10)
Print @CurrentMessage
EXEC master..xp_logevent 12345678, @CurrentMessage, ERROR
It then enters all the lines
Gary Lowe 
VB6 (Enterprise) SP5
ADO 2.6
SQL Server 7 SP3
OK I know my spelling and grammer is crap so don't quote me on it!
To err is human to take the P! is only natural !!
Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|