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
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With