Domanda

I executed a Stored Procedure in SQL Server Management Studio 2005 but then i didn't check if the Stored Procedure executed succesfully. I used below command:

exec [Stored Procedure name] '[param1]' , '[param2]'

Now, i want to find :

a) if the Stored Procedure executed succesfully

b)what were the results from this execution

I could not find any relevant documentation. Can you help?

È stato utile?

Soluzione

One other way would be to put the entire body of the sp into an try-catch block. At the end of the try, insert into an audit/log table some values that you are interested in (eg: scope_identity for inserts, plain text like 'Done!', some time stamps to see when it was ran, etc..) while in the catch you do the same but with different values depending on your needs: ERROR_MESSAGE, ERROR_NUMBER, 'Error occurred!', etc. There are plenty of ways to 'audit' a stored procedure, you just need to pick one that best suits your needs.

Altri suggerimenti

if these are SELECT only, you can only see the output in Result Pane of SSMS or in the application that call the stored procedure. In the server the records will be loaded (cached).

To see what is cached in SQL Server memory, see this page What is cached by sql server

This can give you some insight on when the SP was last called

SELECT qt.[text] AS [SP Name], 
       qs.last_execution_time, 
       qs.execution_count AS [Execution Count] 
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
WHERE qt.dbid = db_id() -- Filter by current database
AND qt.text LIKE '%YourSPName%'

Unless the SP has WITH RECOMPILE, it should be in the cache if it is being used (unless something has happened to flush the cache). However, finding the results that were returned, after the fact is not possible, I think. You can re-execute the SP and check by running a trace, I guess

Rewrite the query presumably an insert/update as a select and enter the parameters you entered. This way would be ok if there are audit fields on the table that are updated by the stored proc. Otherwise querying dm_exec_query_stats is fine provided you have the required permissions.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top