October 21, 2010 at 3:34 am
after a query in management studio, i get a result and a information,how can i transer the information message to a sql file by any cmd or function or sp? thanks
October 21, 2010 at 1:43 pm
Check if the "Results to File" option in SSMS meets your requirement.
Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
October 21, 2010 at 7:52 pm
thank you ,but i want a function or procedure to meet that
October 21, 2010 at 8:18 pm
lvzheng (10/21/2010)
thank you ,but i want a function or procedure to meet that
you won't be able to capture the messages via TSQL. the information is generated, but not capturable via TSQL.
you'll need to copy/paste them manually, or as Adiga suggested, when using SSMS and Text mode, you can capture results to file.
outside of that, if you can write something in .NET, you have to add an eventAddHandler on the SQL connection.InfoMessage, then you could write something to automatically log any messages that hit the connection.
that's actually the same way SSMS does it (to put the messages in the Message tab window); it's just SSMS is not set up to log the messages.
Lowell
October 21, 2010 at 10:34 pm
You can always raise an error to the SQL log file.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 22, 2010 at 12:12 am
got it .thank you
October 22, 2010 at 12:33 am
You can also use "xp_logevent"
like: EXEC xp_logevent 60000, <<your message>>, informational
It Logs a user-defined message in the SQL Server log file and in the Windows Event Viewer. xp_logevent can be used to send an alert without sending a message to the client.
Thanks
October 22, 2010 at 1:24 am
then how can i get them from Windows Event Viewer?
October 22, 2010 at 6:50 am
lvzheng (10/22/2010)
then how can i get them from Windows Event Viewer?
xp_readerrorlog. See the following article for a bit more information...
http://www.sqlteam.com/article/using-xp_readerrorlog-in-sql-server-2005
BUT, now that you've said that, WHY do you feel it necessary to write something to a text file only to read it using T-SQL later on? Why not just write to a table to begin with?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 22, 2010 at 7:01 am
Jeff's right on target.
no matter what, if a message was generated by SQL(i.e. #row(s) affected or PRINT statements), you cannot read it into a variable with TSQL, whether you wanted to use the xp_* functions or not.
If you are trying to capture error messages raised, that is certainly possible, without trying to fiddle with messages at all.
you can use the @@ROWCOUNT to buidl the same message SSMS does.
If you are printing something, you can insert it to a table instead of using print.
The better question is what are you trying to do that you think you need to capture the messages?
Lowell
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply