Saving concurrently on DB?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VMI

    Saving concurrently on DB?

    I'm working on a web application that will store employees on to a sql server
    db. My Employee class consists of several variables (emplcode, fname, lname,
    lname2) and everytime the user saves a new employee, it'll fill all those
    variables and do an SQL INSERT. Is this the best way to store data when
    several users are inserting "concurrent ly"? For example, what would happen if
    user1 clicks "Finish" and starts the DB insertion process and, while it's
    inserting, user2 clicks on "Finish"? Do I need code to manage the fact that
    two users are inserting at the same time?

    Thanks.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Saving concurrently on DB?

    VMI,

    You don't have to necessarily handle the fact that two users are trying
    to do the same thing at the same time. SQL Server will take care of that
    for you.

    However, what you do have to worry about is the user failing the
    database operation when someone beats you to it. Since .NET is a
    disconnected data model, meaning, you load the data, change it, then save it
    back, it is possible that someone might have changed the database before you
    get a chance to save it back. If you save your info, you will be
    overwriting any changes that the user before you made.

    To handle that you need to place something on your table, a timestamp of
    some sort (binary, or a date) and check it when you update the table. You
    basically check to see if the timestamp is different from the value you have
    now. If it is, then you don't update the record, and you inform the user
    that someone else has updated the record they were working on.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "VMI" <VMI@discussion s.microsoft.com wrote in message
    news:B58B01D4-1E5A-4F6D-8876-1153DF6F20A3@mi crosoft.com...
    I'm working on a web application that will store employees on to a sql
    server
    db. My Employee class consists of several variables (emplcode, fname,
    lname,
    lname2) and everytime the user saves a new employee, it'll fill all those
    variables and do an SQL INSERT. Is this the best way to store data when
    several users are inserting "concurrent ly"? For example, what would happen
    if
    user1 clicks "Finish" and starts the DB insertion process and, while it's
    inserting, user2 clicks on "Finish"? Do I need code to manage the fact
    that
    two users are inserting at the same time?
    >
    Thanks.
    >

    Comment

    Working...