我正在执行一个没有返回值的存储过程。如何检查它是否已被执行?这是代码:
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();
这是存储过程:
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
答案 0 :(得分:5)
使用ExecuteNonQuery()
时,存储过程将返回“受影响的行数”:
DbCommand cmd = dbConnection.CreateCommand();
cmd.CommandText = "h_AS_SP_ResetUnfinishedJobs";
cmd.CommandType = CommandType.StoredProcedure;
int rowsAffected = cmd.ExecuteNonQuery();
这将让您了解是否有任何事情已经完成。但是:如果不影响任何行也是存储过程的有效结果,则无法真正使用该返回值来检查它是否已运行。
除此之外:除非发生异常,否则电话可能会有效!