Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Managing concurrency in Linq/SQL

Managing concurrency in Linq/SQL

Scheduled Pinned Locked Moved Design and Architecture
csharpasp-netdatabaselinqsysadmin
23 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    R1911 wrote:

    Though 'Transaction' takes care of things, it still needs us to know how to handle the exceptions.

    You show the error to the user. Something like "this app lets two people change the same text, and then can only save one of them".

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

    R Offline
    R Offline
    R1911
    wrote on last edited by
    #14

    Eddy Vluggen wrote:

    Something like "this app lets two people change the same text, and then can only save one of them".

    Mate, please don't mistake. But I'm not sure why your replies are consistently sarcastic. Do you think I can apply this solution?

    P L 2 Replies Last reply
    0
    • R R1911

      Eddy Vluggen wrote:

      Something like "this app lets two people change the same text, and then can only save one of them".

      Mate, please don't mistake. But I'm not sure why your replies are consistently sarcastic. Do you think I can apply this solution?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #15

      He's not being sarcastic. You are mixing two cases here: The first case is handled through transactions which is where two records attempt to update the same record at the same time. The second case requires more of an end user experience type of mindset and relates to the question, what happens when you have two people editing the same record but they save at different times? Consider a stock trading application. You ring trader A and tell him you want to sell a million dollars of stock. So, he gets your stock up and enters a sell order for a million dollars but then gets distracted. Now, you're watching the market and you see that selling that much stock is going to be a bad idea and you also see that you haven't sold it yet so you ring up the same trading company but get put through to trader B instead. Now, you tell trader B to just sell half a million dollars of this stock. That trader gets up the stock, sets it and processes the order and you have just sold half a million. Now trader A comes back from his very enjoyable lunch and notices that he hasn't placed the order so he presses Sell. What happens next is hugely important. If your application treats each "transaction" atomically and just processes it, you have just sold 1.5 million dollars of stock when you only wanted to sell 1/2 a million. If your system is clever and checks the updates, it detects that another transaction has occurred after you started and prompts you. Hopefully this causes you to ring the customer and check whether they wanted to sell 1/2, 1 or 1 1/2 dollars of stock. That's what Eddy was getting at.

      This space for rent

      R 1 Reply Last reply
      0
      • R R1911

        I'm an old systems programmer. Now forced to do some fancy DB projects. So trying to figure out, how things work.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #16

        You hit a multitude of topics; related and unrelated. Without more focus, you made it near impossible to give you a "straight" answer.

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        R 1 Reply Last reply
        0
        • L Lost User

          You hit a multitude of topics; related and unrelated. Without more focus, you made it near impossible to give you a "straight" answer.

          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

          R Offline
          R Offline
          R1911
          wrote on last edited by
          #17

          lol I see it now, when I read my question again. :) My own experience is all about putting Critical sections & mutex to use to handle similar scenario's without involving DB. I was all thinking to control just with plain client code. Just like ensuring the entry gate is atomically protected or ensuring the calls reaches sequentially there through a proper queue. But Linq/SQL providing features out of the box, is awesome.

          1 Reply Last reply
          0
          • P Pete OHanlon

            He's not being sarcastic. You are mixing two cases here: The first case is handled through transactions which is where two records attempt to update the same record at the same time. The second case requires more of an end user experience type of mindset and relates to the question, what happens when you have two people editing the same record but they save at different times? Consider a stock trading application. You ring trader A and tell him you want to sell a million dollars of stock. So, he gets your stock up and enters a sell order for a million dollars but then gets distracted. Now, you're watching the market and you see that selling that much stock is going to be a bad idea and you also see that you haven't sold it yet so you ring up the same trading company but get put through to trader B instead. Now, you tell trader B to just sell half a million dollars of this stock. That trader gets up the stock, sets it and processes the order and you have just sold half a million. Now trader A comes back from his very enjoyable lunch and notices that he hasn't placed the order so he presses Sell. What happens next is hugely important. If your application treats each "transaction" atomically and just processes it, you have just sold 1.5 million dollars of stock when you only wanted to sell 1/2 a million. If your system is clever and checks the updates, it detects that another transaction has occurred after you started and prompts you. Hopefully this causes you to ring the customer and check whether they wanted to sell 1/2, 1 or 1 1/2 dollars of stock. That's what Eddy was getting at.

            This space for rent

            R Offline
            R Offline
            R1911
            wrote on last edited by
            #18

            Thanks, sorry may be I read him wrong. thanks for the neat explanation. :thumbsup:

            1 Reply Last reply
            0
            • R R1911

              Eddy Vluggen wrote:

              Something like "this app lets two people change the same text, and then can only save one of them".

              Mate, please don't mistake. But I'm not sure why your replies are consistently sarcastic. Do you think I can apply this solution?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #19

              R1911 wrote:

              Mate, please don't mistake. But I'm not sure why your replies are consistently sarcastic.

              They're not meant to be sarcastic, but I can see how they could come across like that. Someone could have deleted the record you tried to update. How should the computer recover from that automagically, without resorting to assumptions about one of the two conflicting updates? How DO you update a record that no longer exists? Depending on what you are doing, there should be *very little* chance ever for two users simultaneous working on the same recordset. A neat solution I've seen would open the forms in read-only mode when someone else was working on that record, including the time they opened it "for editing".

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              R 1 Reply Last reply
              0
              • R R1911

                I have a column in an SQL table, whose values might be updated by multiple clients at the same time. All clients access DAL through Asp.net WebAPIs + Win Form application. How do we ensure , only one client updates the value at a time consistently? If it's a client side code, I would just use locks/Mutex . How do we do this in server? I guess "static" methods are a poor option. Should I go for any Queuing mechanism? Please suggest what's the right method to handle this simple concurrency requirement.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #20

                Please be very sure this is a real use case, it is often identified as a problem by management or an inexperienced developer as something that can/might happen but they have no real idea if the application requires this level of engineering.

                Never underestimate the power of human stupidity RAH

                R 1 Reply Last reply
                0
                • M Mycroft Holmes

                  Please be very sure this is a real use case, it is often identified as a problem by management or an inexperienced developer as something that can/might happen but they have no real idea if the application requires this level of engineering.

                  Never underestimate the power of human stupidity RAH

                  R Offline
                  R Offline
                  R1911
                  wrote on last edited by
                  #21

                  Sure. thanks. I'll try to share a pic of what I originally thought.

                  1 Reply Last reply
                  0
                  • L Lost User

                    R1911 wrote:

                    Mate, please don't mistake. But I'm not sure why your replies are consistently sarcastic.

                    They're not meant to be sarcastic, but I can see how they could come across like that. Someone could have deleted the record you tried to update. How should the computer recover from that automagically, without resorting to assumptions about one of the two conflicting updates? How DO you update a record that no longer exists? Depending on what you are doing, there should be *very little* chance ever for two users simultaneous working on the same recordset. A neat solution I've seen would open the forms in read-only mode when someone else was working on that record, including the time they opened it "for editing".

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    R Offline
                    R Offline
                    R1911
                    wrote on last edited by
                    #22

                    Got it. :thumbsup: thanks! And excuse the misread. :)

                    L 1 Reply Last reply
                    0
                    • R R1911

                      Got it. :thumbsup: thanks! And excuse the misread. :)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #23

                      You're welcome, and no problem; I know I'm not good with humans :D

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups