R
root_zh
Unregistered / Unconfirmed
GUEST, unregistred user!
现在的问题是:我想用事务锁定某一条记录,使其它用户在用锁读取时读取不到该数据,在这种情况下,在事务开始读取后,在查询分析器中读取没有问题,但是用delphi 7中的ado读取时,仍然可以读取到,这是什么原因呢?<br>adoconnection.IsolationLevel是:ilSerializable<br>带事务读取数据:<br>begintransaction,<br>sql语句为:SELECT * FROM t_user WITH (UPDLOCK) WHERE ID=105<br>执行到此处,在查询分析器中用"SELECT COUNT(*) FROM t_user WITH(UPDLOCK,READPAST) WHERE ID=105"读取的结果是0,<br>而在应用程序中:<br>var<br> ds : TADODataSet;<br> dbConn : TADOConnection;<br> cm : TADOCommand;<br>begin<br> dbConn := TADOConnection.Create( nil <br> cm := TADOCommand.Create( nil <br> ds := TADODataSet.Create( nil <br> dbConn.ConnectionString := self.ADOConnection1.ConnectionString;<br> cm.Connection := dbConn;<br> dbConn.IsolationLevel := ilSerializable;<br> dbConn.Open( 'sa','fullsoft' <br> cm.CommandText := 'SELECT COUNT(*) FROM t_user WITH(UPDLOCK,READPAST) WHERE ID=105';<br> ds.Recordset := cm.Execute;<br> ShowMessage( IntToStr( ds.RecordCount  <br> cm.Free;<br> dbConn.Close;<br> dbConn.Free;<br>end;<br>却能读取到1.这是什么原因呢?