ExecuteReader requires command to have transaction when connection assigned to command is in pending local trans

前端 未结 2 361
遥遥无期
遥遥无期 2021-01-17 08:46

i have to insert in two tables with single transaction, query which have to implement are below. secondly getting exception at SqlDataReader read = comm.ExecuteR

2条回答
  •  北海茫月
    2021-01-17 09:21

    You might want to consider switching to using TransactionScope which is then used implicitly for all commands within it. You'd use it something like:

    using(var scope = new TransactionScope())
    {
       using(var conn = new SqlConnection(/*...*/))
       {
          //As many nested commands, etc, using the above connection.
          //but don't need to create a SqlTransaction object nor
          //in any way reference the scope variable
       }
       scope.Complete();
    }
    

提交回复
热议问题