Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check that a stored procedure with no return value has been executed?

I am executing a stored procedure that has no return value. How can I check that it has actually been 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
like image 364
Kasper Hansen Avatar asked Nov 29 '25 21:11

Kasper Hansen


1 Answers

The stored proc will return a "number of rows affected" when using 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 whether or not anything has even been done. However: if not affecting any rows also is a valid outcome for your stored proc, you cannot really use that return value to check if it's been run.

Other than that: unless an exception occurs, the call presumably worked !

like image 148
marc_s Avatar answered Dec 01 '25 11:12

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!