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

前端 未结 2 389
遥遥无期
遥遥无期 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条回答
  •  猫巷女王i
    2021-01-17 09:35

    problem is you execute cmd1 on the same connection as cmd so there is an open transaction on that connection but you don't set cmd1.Transaction ... so solution would be to

    cmd1.Transaction = transaction;
    

    before

    cmd1.ExecuteNonQuery();
    

提交回复
热议问题