none
sharing TableAdapter instance RRS feed

  • Question

  • Hello,

    I was wondering if it's OK to share a TableAdapter instance.

    What are the general rules why you wouldn't want to do this?

     

    For example, what happens if I use BeginTransaction(), set update \ select command to use the transaction and at this moment, before calling Commit(),  I am using the TableAdapter instance from another thread (let's say only doing a Select)

    Does this mean the selects & updates done from thread will also be done using transaction?

    Generally, I need some advice about recommended ways regarding TableAdapter instances.

    Thanks.

    Tuesday, August 17, 2010 5:17 PM

Answers

  • Hi Andrewns,

     

    Since each TableAdapter is typically associated with one DataTable(DataSet), and although DataTable(DataSet) is safe for multithreaded read operations, you must synchronize any write operations. The TableAdapter's Update() method calls AcceptChanges() on the DataSet, and that's a write operation. In additon, if you use the TableAdapter instance from another thread(doing a Select) before calling Commit(), the data in datatable may not be synchronized, and it may cause concurrency problem when call the TableAdapter.Update() method in different threads.

    You can refer to the following thread to get some additional information.

     

    http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/58b36465-3b6a-4883-a847-3c5f61fe886a

     


    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, August 18, 2010 5:41 AM
    Moderator

All replies

  • Hi Andrewns,

     

    Since each TableAdapter is typically associated with one DataTable(DataSet), and although DataTable(DataSet) is safe for multithreaded read operations, you must synchronize any write operations. The TableAdapter's Update() method calls AcceptChanges() on the DataSet, and that's a write operation. In additon, if you use the TableAdapter instance from another thread(doing a Select) before calling Commit(), the data in datatable may not be synchronized, and it may cause concurrency problem when call the TableAdapter.Update() method in different threads.

    You can refer to the following thread to get some additional information.

     

    http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/58b36465-3b6a-4883-a847-3c5f61fe886a

     


    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, August 18, 2010 5:41 AM
    Moderator
  • Hi Andrewns, 

    I'm writing to follow up the post. Does the above suggestion work?

    Please feel free to let me know if you need any help.

    Best regards,
    Alex Liang

    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Sunday, August 22, 2010 4:46 AM
    Moderator
  • Hi Andrewns,

    I am marking my reply as answer. If you have any question, please feel free to let me know.

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 24, 2010 10:19 AM
    Moderator