1

I understand that rpc_completed is defined as the completion of a remote procedure call and sql_batch_completed is the completion of a t-sql batch. However can anyone explain in concrete terms what the difference is? When should I use one and when should I use the other? Will most/all SQL commands trigger both events?

Kenneth Fisher
  • 24,127
  • 12
  • 61
  • 114

1 Answers1

5

The difference is how the command is executed by the client. The client can directly execute a stored procedure or the client can send a sql batch.

To call a stored procedure from .NET you would use

SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.StoredProcedure;

and to execute a batch you would use

SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.Text;

There are other things you need to set up like the connection, but the above shows the difference between the two execution modes.

Sebastian Meine
  • 9,125
  • 1
  • 27
  • 32
  • So if I want catch every time a system SP is called I'll want to capture both rpc_completed and sql_batch_completed? Are there any other events I should capture? – Kenneth Fisher Nov 06 '13 at 20:33
  • if you just want to capture the fact that it was executed, i would use the sp_completed (or sqlserver.module_end for XE) event. If you are interested in the parameters too, have a look at http://sqlity.net/en/976/capturing-parameters-of-a-stored-procedure-call/ – Sebastian Meine Nov 06 '13 at 20:42
  • Also, read about how to capture parameter values here: https://www.scarydba.com/2018/09/24/extended-events-and-stored-procedure-parameter-values/ – Venkataraman R May 28 '20 at 07:40