locked
lock the SQL Server RRS feed

  • Question

  • I have an application which will be used by different users the same time and I am using SQL Server 2008 Express. In myT-SQL, I want to create an account number ofr the user..

    How can I make sure that during this process no other user will have the same account number?

    I mean what if another users was online and trying to create an account number?

    is there nay way to lock the process on SQL Server until the current process is over BUT without throwing an error on my windows C# application?


    Jassim Rahma
    Wednesday, December 30, 2009 9:50 AM

Answers

All replies

  • You can create a procedure for the next account number generation and use sp_getapplock and sp_releaseapplock system stored procedures  to make sure that it is not being executed by different session. You can also specify the wait time for the other sessions to wait for the lock to be released before terminating the current call.
    Wednesday, December 30, 2009 9:59 AM
  • You can also use optimistic concurrency control with rowversion (former name timestamp):


    Kalman Toth, SQL Server & BI Training, SSAS, SSIS, SSRS; http://www.SQLUSA.com
    • Marked as answer by Zongqing Li Tuesday, January 5, 2010 8:44 AM
    Wednesday, December 30, 2009 10:31 AM