Friday, February 24, 2012

Capture messages from extended procedure

Hi all,

I am using an extended stored procedure that sends email using SMTP. The procedure can be downloaded here (http://www.sqldev.net/xp/xpsmtp.htm). If I execute the procedure in QA and it fails for some reason, the error message is printed in the Messages tab. Is there any way to capture this message/messages when I use the XP in my stored procedures?

Your help is much appreciated.Anybody?

Forgive me for bumping, I promise never to do it again, but it's important for me to find out if this is possible.|||Yes, it is possible to capture the "print vector" output of an extended stored procedure within a standard stored procedure, but it isn't simple.

The easiest way is to use xp_cmdshell to execute OSQL.EXE and capture its output into a table. This is untested, but you'll get the idea:CREATE TABLE #foo (
x VARCHAR(1024)
)

INSERT INTO #foo (x)
EXECUTE master.dbo.xp_cmdshell 'OSQL -E -Q"EXECUTE sp_who"'

SELECT * FROM #fooMy next choice would be to create a DTS package that uses Active-X script to do roughly the same thing. That's more complicated than I want to type right now, but it isn't too hard.

There are other ways that break even more "best practices", but lets not go there unless we really have to!

-PatP|||Thanks for your reply.

It actually works :) :cool: !!! Perhaps it's just me, but don't like the idea to use xp_cmdshell.

Anyway, thank you for you time and expertice. :D

No comments:

Post a Comment