none
LINQ to SQL concurrency RRS feed

  • Question

  • <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin-top:0in; margin-right:0in; margin-bottom:10.0pt; margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} .MsoPapDefault {mso-style-type:export-only; margin-bottom:10.0pt; line-height:115%;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->

    I have a server (multi threaded) that I built witch updates a table in a db (SQL server).  This server can have requests for many clients, and those clients can try to update the same record.  I am trying to resolve the best way to deal with the following scenario:

    Client one connects

      Client one selects record ‘a’

    Client two connects

    Client two selects record ‘a’

    Client one updates record ‘a’ and submits

    Client two updates record ‘a’ and submits

    An exception is thrown.

     

     

    What is the best way to lock these record to prevent this situation?  I am  using LINQ to SQL.  Blocking the code in a transaction does not seem to work.  Do I need to use a ‘lock’statement?

     

    Thoughts?

    Thanks KO

     

    Monday, June 15, 2009 5:04 PM

Answers

  • There is no need in the lock statement. LINQ to SQL means optimistic concurrency, when the conflict is found at the moment of update, for example, see here
    See also the MSDN entries about ColumnAttribute.UpdateCheck, ColumnAttribute.IsVersion, DataConflicts.ChangeConflicts.
    Tuesday, June 16, 2009 8:28 AM

All replies

  • There is no need in the lock statement. LINQ to SQL means optimistic concurrency, when the conflict is found at the moment of update, for example, see here
    See also the MSDN entries about ColumnAttribute.UpdateCheck, ColumnAttribute.IsVersion, DataConflicts.ChangeConflicts.
    Tuesday, June 16, 2009 8:28 AM
  • Thanks...
    Wednesday, June 17, 2009 9:05 PM