Results 1 to 14 of 14

Thread: Database Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Database Question

    In my project I build up the DB section and I'm building the GUI. As my project has to work in a LAN, I'm facing now with the problem of the same request from two different clients, in the sense that both clients request the same record for modifying it. I use data in disconnected mode. How can I manage this problem? I don't have idea on that, any help is appreciate.

    Thx a lot,
    Xmas
    Learn, this is the Keyword...

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    You have answered the question yourself. Disconnected data model. If by a little chance two users try to update one record at exactly the same time, i think SQL Server (or MSDE which is proably your backend database server) will handle the transaction.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    My program is well structured, so it's impossible that two users will update the database in the same time... The problem is that two users access the same record the same time for modifying. The first finishes and update the database. The second, that is still working on it, has now "a bad version" of the record (the old, because the new one is which the first updated) , and updating will overwrite the work of the first. I was asking about that.

    Thx
    Learn, this is the Keyword...

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    If this happens the program will throw a DBConcurrency exception. You can address this in 3 ways, overwrite the data or you can have a form presented to the user with the new data and the current data and ask if they want to keep the new data or overwrite it, or you can just go ahead and lock that row when its being updated.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Ok, I just thrown this exception... So the Update method must be in a try catch block. If I want to discard the changes I do nothing. What if I want to overwrite?
    Learn, this is the Keyword...

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    The second, that is still working on it, has now "a bad version" of the record (the old, because the new one is which the first updated) ...
    I guess you are running a competetion in your program Think about this situation:
    User A and B access the same time a record and want to modify a data of the Column called 'Name'
    1- User A and B read then 'Name' and its ="Xmas79"
    2-User A modifes it and updates it, 'Name' is now changed to "Xmas74"
    3-User B still thinks that 'Name' has not changed and modifies it to 'Xmas80' and updates it.
    4-Name is now 'Xmas80'
    Okay, but what should the filed 'Name' should be? The one that User A has enterd or the one that User B? Are they supposed to enter different data? If yes who has the priority, if not why two user are assgined to modify at a same time? and what will happen that user B tries to update the row with the same data is what DEVGREP said and that is DBConcurrency exception.You can 'use optimistic cuncurrency' when building your dataadapters.
    Last edited by Lunatic3; May 13th, 2003 at 11:08 AM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Yes, it's like that. But as DEVGRP said, your step 4 will never be executed because an exception is thrown. I cannot know what the data must be, users will know, but as programmer, I have to be aware from all the pessimistic things that can happen, like this one, isn't it? I have to look more in detail your advice... in the meanwhile, other ideas/suggestions/jokes are welcome

    Xmas.
    Learn, this is the Keyword...

  8. #8
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    As i told you try to implement "use optimistic cuncurrency" . To test it add a datadapter to your form at desing time and run a query builder and remove the tick for 'use optimistic cuncurrency' . Then look at the wizard generated update command. Then go back and use it now and again look at the update command. You will see the difference.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Ok, thanks. I'll do it later, maybe tomorrow, now I've to do other things... Sure I'll let you know.

    Best regards,
    Xmas79
    Learn, this is the Keyword...

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Lunatic3, I tried to do what you say. I can see the differences, depending on the complexity of the table they can be a LOT!!! Do I have to do it by code? Is there another way, like a method, a property in the dataadapter??

    Thx
    Learn, this is the Keyword...

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Or DEVGRP, If I update it will thrown always that exception. How to overwrite?

    Thx
    Learn, this is the Keyword...

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Talking *** BUMP ***

    *** BUMP ***
    Learn, this is the Keyword...

  13. #13
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Do I have to do it by code?
    If you are a coder then YES
    Anyway you can add adapters at desing time, not run time. However DEVgrp method would be fine too. Try catching the exception and then deal with it. In that case try to catch the most specific exception.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Learn, this is the Keyword...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width