我正在尝试将事务提交到我的sql Server 2008数据库 – 首先是2次插入然后是几次更新,但是,只要它尝试执行第一次更新,我就会收到以下错误:
@H_404_2@
ExecuteNonQuery requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction.
The Transaction property of the command has not been initialized.
这是代码,为简洁起见略有编辑:
using (_cn) { _cn.Open(); IDbTransaction transaction = _cn.BeginTransaction(); topicId = (int)_cn.Query<decimal>(qAddTopic,new { pForumId = topic.ForumId },transaction).Single(); postId = (int)_cn.Query<decimal>(qAddPost,new { pTopicId = topicId },transaction).Single(); _cn.Execute(qUpdateForums,new { pLastPostId = postId }); _cn.Execute((qUpdateSiteTotals)); transaction.Commit(); }
前2个插入工作正常,但只要它尝试执行其中一个更新,就没有快乐.