How to verify that a stored procedure without a return value has been executed?

I am executing a stored procedure that has no return value. How can I verify that it was actually executed? Here is the code:

this.dbProviderFactory = DalFactory.GetFactory(this.adapterConfiguration);
DbConnection dbConnection = dbProviderFactory.CreateConnection();

dbConnection.ConnectionString = this.adapterConfiguration.DatabaseInformation.ExternalDatabaseInformation.connectionString;
dbConnection.Open();

DbCommand cmd = dbConnection.CreateCommand();
cmd.CommandText = "h_AS_SP_ResetUnfinishedJobs";
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();

And here is the stored procedure:

ALTER PROCEDURE [dbo].[h_AS_SP_ResetUnfinishedJobs]
AS
BEGIN
 -- Delete all unfinished jobs where the force flag has not been set...
 DELETE FROM h_AS_mds_MetaDataStatus
 WHERE mds_status NOT IN (11,12) AND mds_force = 0
END
+3
source share
1 answer

The stored procedure will return "number of rows affected" when you use ExecuteNonQuery():

DbCommand cmd = dbConnection.CreateCommand();
cmd.CommandText = "h_AS_SP_ResetUnfinishedJobs";
cmd.CommandType = CommandType.StoredProcedure;
int rowsAffected = cmd.ExecuteNonQuery();

This will give you an idea of ​​what else was it done. However: if you do not affect any lines, this is also the correct result for the stored proc, you cannot use this return value to check if it is running.

: , !

+5

Source: https://habr.com/ru/post/1782749/


All Articles