提交数据失败 Commit transaction请求没有对应的Begin transaction
错误提示如标题,数据库使用的是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();
}
}