Results 1 to 4 of 4

Thread: SQL Guru's

  1. #1

    Thread Starter
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621

    Unhappy 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


  2. #2

    Thread Starter
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Guess not then
    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


  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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

    BOFH Now, BOFH Past, Information on duplicates

    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...

  4. #4

    Thread Starter
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    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
  •  



Click Here to Expand Forum to Full Width