String lastcph = "";
        SqlConnection myConnection = new SqlConnection(EDb.CnnString);
        myConnection.Open();
        // 启动一个事务
        SqlTransaction myTrans = myConnection.BeginTransaction();
        // 为事务创建一个命令
        SqlCommand myCommand = new SqlCommand();
        myCommand.Connection = myConnection;
        myCommand.Transaction = myTrans;
        try
        {
           ... //这里进行了一些数据库操作
           ...
           //myTrans.Commit();这里把事务提交屏避了
          
        }
        catch (Exception Ex)
        {
            //myTrans.Rollback();这里把事务回滚屏避了
        }
        finally
        {
            myTrans.Dispose();
            myConnection.Close();
            myConnection.Dispose();
           //清除事务,并清除数据链接
        }那在上面的操作中,“这里进行了一些数据库操作” 这里的操作会如何执行
谢谢麻烦分析一下
谢谢

解决方案 »

  1.   

    事务内产生的锁好像会一直保留,脏读什么的就出来了,阻塞啊,死锁啊。。最好是 设定下显式提交 SET   IMPLICIT_TRANSACTIONS  ON 
    这样如果链接断开而事务没提交的话,会自动回滚
      

  2.   

    sql默认事务隔离级别是不能读未提交的数据,一事务没有提交,其它的事务不能读,只能等待;
      

  3.   

    sql默认事务隔离级别是不能读未提交的数据,一事务没有提交,其它的事务不能读,只能等待;
    -----------------------
    但我这里后面已经关掉了链接了啊
    谢谢
      

  4.   

    以下摘自MSDN:
    Call the Commit method of the SqlTransaction object to complete the transaction, or call the Rollback method to abort the transaction. If the connection is closed or disposed before either the Commit or Rollback methods have been executed, the transaction is rolled back.http://msdn.microsoft.com/zh-cn/netframework/2k2hy99x(en-us,VS.85).aspx
      

  5.   

    断开连接后,Sql服务器会回滚这个未提交的事务
      

  6.   


    lz所进行的事务的语句获取的相关锁的级别和性质了,原来的事务没有提交就会一直占用资源执行的,比如你update一条明确的记录,这时根据你的隔离级别不同,这条记录有可能能被访问,有可能不能被访问。