前台是使用了事务调用的存储过程中又有事务,这样可行吗?会不会超级影响效率,sqlserver数据库很多人同时用到这个存储过程,因为前台还要同时执行其他的命令和操作,大虾们!事务存储sqlserver数据库c#

解决方案 »

  1.   

    那样使用是没有问题的,参考:public ExecuteResult ExecuteNonQuery(SqlCommand sqlCommand)
    {
        ChangeNullToDBNullValue(sqlCommand);
        bool useDefaultConnection = false;
        if (sqlCommand.Connection == null)
        {
            useDefaultConnection = true;
            sqlCommand.Connection = new SqlConnection(this.connectionString);
        }
        else
        {
            useDefaultConnection = false;
            if (sqlCommand.Connection.State != ConnectionState.Closed)
            {
                throw new ArgumentException("SqlCommand's connection state must be closed.");
            }
        }
        sqlCommand.Connection.Open();
        sqlCommand.Transaction = sqlCommand.Connection.BeginTransaction();
        try
        {
            int rows = sqlCommand.ExecuteNonQuery();
            sqlCommand.Transaction.Commit();
            return new ExecuteResult() { ActionStatus = ActionStatusType.Success, ReturnValue = rows };
        }
        catch (SqlException ex)
        {
            sqlCommand.Transaction.Rollback();
            DBOperatorLogsWritter.WriteDBErrorLog(ex, sqlCommand);
            return new ExecuteResult() { ActionStatus = ActionStatusType.Fail, Message = ex.Message };
        }
        finally
        {
            sqlCommand.Connection.Close();
            if (useDefaultConnection)
            {
                sqlCommand.Connection = null;
            }
        }
    }
      

  2.   

    你存储过程里都有事务了 后台就不需要写了 直接调用就行了..如果还害怕有问题 大不了在存储过程里加 try catch 这样就行了