Enabling MARS prevents the saving of records

i got error like this

PDOException

SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back.

how to fix it?? please help me :-[

public function actionCreate() {

    $model = new CustomerTransactions();


    $model2 = new CustomerTransactionDetails();





    $connection = Yii::$app->db;


    $transaction = Yii::$app->db->beginTransaction();


    try {


        if ($model->load(Yii::$app->request->post())) {





            $command = Yii::$app->db->createCommand("spSetCustomerTransaction @custId =:CustId, @isProcessed =:isProcessed, @transactionNumber");


            $command->bindParam(':CustId', $model->CustId = Yii::$app->user->identity->username);


            $command->bindValue(':isProcessed', $model->IsProcessed = '0');


            $command->bindParam(':transactionNumber', T_DEFAULT, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, '');


            $command->execute();


            $valueOut = Yii::$app->db->createCommand("select @transactionNumber as result;")->queryScalar();

// transaction detail //

            $command = Yii::$app->db->createCommand("spSetCustomerTransactionDetails @transactionNumber =:, @proID =:proID, @quantity=:quantity");


            $command->bindParam(':transactionNumber', $valueOut);


            $command->bindValue(':proID', $model2->proId = 'MCCO');


            $command->bindValue(':quantity', $model2->Quantity = '12');


            $command->execute();





            $transaction->commit();


            return $this->redirect(['view', 'id' => $model->name]);


        } else {


            throw Exception('Unable to save record.');


        }


    } catch (Exception $e) {


        $transaction->rollback();


    }





    return $this->render('create', [


                'model' => $model,


                'model2' => $model2,


    ]);


}

Please format the code properly otherwise it’s hard to read.




 public function actionCreate() {

        $model = new CustomerTransactions();

        $model2 = new CustomerTransactionDetails();




        if ($model->load(Yii::$app->request->post())) {

            $transaction = Yii::$app->db->beginTransaction();

            try {

                $command = Yii::$app->db->createCommand("spSetCustomerTransaction @custId =:CustId, @isProcessed =:isProcessed, @transactionNumber");

                $command->bindParam(':CustId', $model->CustId = Yii::$app->user->identity->username);

                $command->bindValue(':isProcessed', $model->IsProcessed = '0');

                $command->bindParam(':transactionNumber', T_DEFAULT, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, '');

                $command->execute();

                $valueOut = Yii::$app->db->createCommand("select @transactionNumber as result;")->queryScalar();


// transaksi detail //

                $command2 = Yii::$app->db->createCommand("spSetCustomerTransactionDetails @transactionNumber =:, @proID =:proID, @quantity=:quantity");

                $command2->bindParam(':transactionNumber', $valueOut);

                $command2->bindValue(':proID', $model2->proId = 'MCCO');

                $command2->bindValue(':quantity', $model2->Quantity = '12');

                $command2->execute();


                if ($command->execute()) {

                    $transaction->commit();

                    return $this->redirect(['view', 'id' => $model->id]);

                } else {

                    $transaction->rollback();

                }

            } catch (Exception $e) {

                $transaction->rollback();

                throw $e;

            }

        }

        return $this->render('create', [

                    'model' => $model,

                    'model2' => $model2,

        ]);

    }