Locking

  • Hi

    I want to lock some group of data when some user monitoring this data group on winform. When other user want to monitoring same data i want to throw exception. "This data group open on USER A."

    What i need to do? How do i ensure this model in MS SQL

  • You can add a column to the table called Locked with default value N.

    When you read it for monitoring, change the column value to Y.

    If value is Y, don't allow others to read it.

    Once monitoring it over, revert the value to N

  • Suresh B. (1/11/2012)


    You can add a column to the table called Locked with default value N.

    When you read it for monitoring, change the column value to Y.

    If value is Y, don't allow others to read it.

    Once monitoring it over, revert the value to N

    If you go that route, be very, very, very careful with error handling. Make sure that there's no way that an error can result in the monitoring ending with the locked still set to Y. You may also need a scheduled job to set the locked back to N in case the client crashes or stuff like that.

    If I recall, there's an entire chapter on this in Adam Machanic's "Expert SQL Server 2005 Development" (not the 2008 one). It's far from as simple a most people tend to assume

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Of course i thought this simple model. But it's need to some kind of time out model. As GilaMonster said.

    I interesting maybe sql provide this kind of model in default.

  • You can use the applock feature (see Books Online for details), but it still requires some custom code.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Yes. I read this feature. I'll look what i can do. Thanks

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply