数据库访问时并发冲突如何解决,
一般有程序代码中控制解决和SQL语句(存储过程)解决,哪位高手能从思路上给指点一二,写几句代码,有个小例子就更好了
任意一种方法均可

解决方案 »

  1.   

    最简单的, 用begin tran把你要进行的事务括起来.这样并发的话会自动有锁的.----------------------------------------------------------------------------------------
    欢迎访问我的新站:http://www.FavNet.cn —— 专勤致精 想您所思 专业IT技术服务
    展示技术实力,寻求合作伙伴、合作项目中……
      

  2.   

    调用存储过程时,只要在存储过程中应用begin tran就可以了吧
      

  3.   

    Select * from tbale with(ROWLOCK) where id=2
      

  4.   

    可以用ADO.NET自带的事务处理功能来解决,其代码如下
    SqlConnection conn = new SQLConnection(connectString);
    conn.Open();SqlTransaction tran = conn.BeginTransaction();SqlCommand cUpdate1 = new SqlCommand(sqlUpdate1, conn);    //第一条记录
    SqlCommand cUpdate2 = new SqlCommand(sqlUpdate2, conn);   //第二条记录
    SqlCommand cUpdate3 = new SqlCommand(sqlUpdate3, conn);  // 第三条记录cUpdate1.Transaction = tran;
    cUpdate2.Transaction = tran;
    cUpdate3.Transaction = tran;try
    {
                    cUpdate1.ExcuteNoQuery();
                    cUpdate2.ExcuteNoQuery();
                    cUpdate3.ExcuteNoQuery();                tran.Commit();
    }
    catch(Exception Err)
    {
                    tran.Rollback(); 
    }
    finally
    {
                    conn.Close();
                    conn.Dispose();
    }