private static void ProcessError(SysWorkflowMessage msg, Exception ex, string connectionStringOrName)
 {
     if (string.IsNullOrWhiteSpace(connectionStringOrName))
     {
         connectionStringOrName = DataContext.BizConnectionStringDefault;
     }
     try
     {
         using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
         {
             using (BizDataContext context = new BizDataContext(connectionStringOrName, true))
             {
                 if (msg.State != SysWorkflowMessageStateEnum.Running)
                 {
                     throw new Exception(string.Format("消息ID:{0}的状态不为Running", msg.MessageId));
                 }
                 msg.State            = SysWorkflowMessageStateEnum.Error;
                 msg.LastErrorMessage = ex.Message;
                 string sql = string.Format("UPDATE SysWorkflowMessage SET STATE = {0}, LastErrorMessage = {1} WHERE MessageId = {2} AND (STATE = {3} or STATE = {4}) ", new object[] { context.AddPrefixToParameterName("NewState"), context.AddPrefixToParameterName("LastErrorMessage"), context.AddPrefixToParameterName("MessageId"), context.AddPrefixToParameterName("OldState1"), context.AddPrefixToParameterName("OldState2") });
                 if (context.ExecuteNonQuery(sql, new DbParameter[] { context.CreateParameterWithPrefix("NewState", Convert.ToInt32(SysWorkflowMessageStateEnum.Error), typeof(int)), context.CreateParameterWithPrefix("LastErrorMessage", ex.Message, typeof(string)), context.CreateParameterWithPrefix("MessageId", msg.MessageId, typeof(int)), context.CreateParameterWithPrefix("OldState1", Convert.ToInt32(SysWorkflowMessageStateEnum.Running), typeof(int)), context.CreateParameterWithPrefix("OldState2", Convert.ToInt32(SysWorkflowMessageStateEnum.Inited), typeof(int)) }) <= 0)
                 {
                     AppLogHelper.Information("将工作流消息更改为错误状态时更新行数为0: MessageId={0}", new object[] { msg.MessageId });
                 }
             }
             scope.Complete();
         }
         Console.WriteLine(ex.Message);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception, "将工作流消息更改为错误状态时失败: MessageId={0}", new object[] { msg.MessageId });
         Console.WriteLine(exception.Message);
     }
 }