为什么sqlCommand.ExecuteNonQuery()无法捕获异常

时间:2019-12-02 20:32:55

标签: c# sql-server ado.net

当到达sqlCommand.ExecuteNonQuery()时,当我调试时,它再也没有回到生产线上,并且调试在那里迷路了。它也从来没有到达过陷阱。我在这里想念什么?

public void UpdateSaveAssessmentHistory()
{

    var connectionManager = new ConnectionManager(_vgp);
    var jobId = SAHelper.getNextJobID(connectionManager);
    _parameters.ExtractionType = "SaveAssessmentHistory";
    var logEntries = new List<string>();
    SAHelper.createProgressRecord(connectionManager, jobId, 0, _parameters.ExtractionType);
    var logFileName = SetUpLogFile(connectionManager, _parameters.ExtractionType, jobId);
    var sqlCommand = connectionManager.GetCommand();
    sqlCommand.CommandType = CommandType.StoredProcedure;
    sqlCommand.CommandText = "REAL_PROP.ASSESSMENT_SAVE";
    sqlCommand.Parameters.Add(new SqlParameter("FiscalYear", _parameters.FiscalYear));
    sqlCommand.Parameters.Add(new SqlParameter("FinalSave", _parameters.FinalSave));
    sqlCommand.Parameters.Add(new SqlParameter("RunType", _parameters.RunType));
    sqlCommand.Parameters.Add(new SqlParameter("SaveDate", _parameters.SaveDate));
    sqlCommand.CommandTimeout = 0;
    try
    {
       sqlCommand.ExecuteNonQuery();
       SAHelper.setCompleteforProgress(connectionManager, jobId, "COMPLETED", "SAVE ASSESSMENT HISTORY FINISHED", _parameters.ExtractionType);
    }
    catch (Exception e)
    {
        SAHelper.updateProgress(connectionManager, jobId, "ERROR", e.Message, 0, _parameters.ExtractionType);
        logEntries.Add("Error: " + e.Message);
    }
    finally
    {

        if (logEntries.Count > 0)
            SAHelper.WriteLogFile(logFileName, logEntries);
        sqlCommand.Dispose();
        connectionManager.CloseConnection();
    }
}

0 个答案:

没有答案