提交数据失败 Commit transaction请求没有对应的Begin transaction

liyoujin3 2014-07-02 06:37:08

错误提示如标题,数据库使用的是Sql server2000(Sp4),
以下是相应的代码:请哪位牛人帮帮忙,万分感谢!
SqlTransaction tran = null;
SqlConnection conn = null;
try
{
conn = new SqlConnection(DbHelperSQL.connectionString);

if (conn.State == ConnectionState.Closed)
{
conn.Open();
}

tran = conn.BeginTransaction();

string sqlUpdate = string.Empty;

if (EntryID == 5)
{
sqlUpdate = @"update T_FileDirStruct4Img set AccountListRows=@AccountListRows,AccountListLTX=@AccountListLTX,
AccountListLTY=@AccountListLTY,AccountListW=@AccountListW,AccountListH=@AccountListH,AccountAreaWidth=@AccountAreaWidth
where ImgName=@ImgName";
}
else if (EntryID == 6)
{
sqlUpdate = @"update T_FileDirStruct4Img set AccountListRows2=@AccountListRows,AccountListLTX2=@AccountListLTX,
AccountListLTY2=@AccountListLTY,AccountListW2=@AccountListW,AccountListH2=@AccountListH,AccountAreaWidth2=@AccountAreaWidth
where ImgName=@ImgName";
}

//行数减少,删除多录入的数据
string sqlDel = @"delete from T_AccountListEntriedInfo where EntriedItemID=(select top 1 EntriedItemID from T_DocEntried where DocID=@DocID and EntryID=@EntryID)
and CatalogID=@CatalogID and ImgNo=@PageNo and RowIndex>@AccountListRows-1";

SqlCommand cmmdUpdate = new SqlCommand(sqlUpdate, conn, tran);
SqlCommand cmmdDel = new SqlCommand(sqlDel, conn, tran);
SqlParameter[] pUpdate =
{
new SqlParameter("@AccountListRows",img.AccountListRows),
new SqlParameter("@AccountListLTX",img.AccountListLTX),
new SqlParameter("@AccountListLTY",img.AccountListLTY),
new SqlParameter("@AccountListW",img.AccountListW),
new SqlParameter("@AccountListH",img.AccountListH),
new SqlParameter("@AccountAreaWidth",img.AccountAreaWidth),
new SqlParameter("@ImgName",img.ImgName)
};
SqlParameter[] pDel =
{
new SqlParameter("@DocID",img.DocID),
new SqlParameter("@EntryID",EntryID),
new SqlParameter("@CatalogID",img.Parent_CatalogId),//img是影像节点,Parent_CatalogId是户口号N的ID
new SqlParameter("@PageNo",img.PageNo),
new SqlParameter("@AccountListRows",img.AccountListRows)
};

cmmdUpdate.Parameters.AddRange(pUpdate);
cmmdUpdate.ExecuteNonQuery();

cmmdDel.Parameters.AddRange(pDel);
cmmdDel.ExecuteNonQuery();

tran.Commit();

}
catch (Exception e)
{
tran.Rollback();
throw e;
}
finally
{
if (tran!=null)
{
tran.Dispose();
}
if (conn!=null)
{
if (conn.State==ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}

...全文
592 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧