对于用UPDLOCK读数据后,在查询分析器中读取不到,但用ado控件可读取到,是什么原因呢? ( 积分: 100 )

  • 主题发起人 主题发起人 root_zh
  • 开始时间 开始时间
R

root_zh

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