none
Trying to resolve - Transaction context in use by another session.. RRS feed

  • Question

  • My development enviroment is visual studio 2008.  If using LINQ to SQL in .NET3.5 SP1

    I've got a database service that uses LINQ to SQL table objects to open up tables.  Each  LINQ to SQL table object is a separate project with a LINQ to SQL class file that has a table in it.

    When the service starts up, it ups open each table using the constructor that allows me to pass a sqlconnection object.   Each table gets its own sqlconnection object.   I used the sql connection object because I allow the user to set the userId and password.

     

    These linqtoSQL table objects are global variables in my service.

    Because this service can handle multiple clients at the same time ...  I  have wrapped the logic that updates each table in

    SyncLock "lockobject for the table"

    ''' create new table record

       linqtosqlTableObject.InsertOnSubmit

      linqtosqlTableObject.SubmitChanges

     

    Or

    make my updates to an existing table record

      linqtosqlTableObject.SubmitChanges

    End SynLock.

     

    What I keep getting is Transaction context in use by another session.   I would really think SyncLock/End SyncLock would limit access to a table to one thread at at time.

    Just how long does it take for the TransactionContext used by the LINq to SQL framework to be freed up , say even after the Synclock is freed ?

    I'm thinking that even though I have freed up the sync lock object it, there is still a pending transaction  that need to complete yet ?

     

    What have other people seen ?  Thanks !

     


    Rob Hermann
    Saturday, March 5, 2011 8:45 PM

Answers

  • Hi Rob,

    Since these LINQ to SQL tables are all global objects, all of they should belong to a DataContext object, right?   For DataContext and Transaction in LINQ to SQL, please see this document http://msdn.microsoft.com/en-us/library/bb386995.aspx

    You may consider creating saparete transactions for each unit of work in your app.

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Tuesday, March 8, 2011 7:13 AM
    Moderator
  • This is a bit late but I ended up restructing my service:

    Seeing how i'm sharing my database layer among the clients....

     

    1.  I use stored procedures instead of the linq to SQL table objects for  CRUD operations.  Stored procedures are much faster than the LINQ to SQL table objects.

    2. Each client that comes in gets its own copy of some the stored procedure handles.   The shared storedprocedures variables i have in my database layer gets set to the incoming client copy of the stored procedures.    I have SyncLock objects as well.

    3. I broke up the database updates within the  transactions to more more transactions with less operations instead of less transactions and more operations.

     

     


    Rob Hermann
    • Marked as answer by 10437NiceGuy Tuesday, August 30, 2011 10:00 PM
    Tuesday, August 30, 2011 10:00 PM

All replies

  • Hi Rob,

    Since these LINQ to SQL tables are all global objects, all of they should belong to a DataContext object, right?   For DataContext and Transaction in LINQ to SQL, please see this document http://msdn.microsoft.com/en-us/library/bb386995.aspx

    You may consider creating saparete transactions for each unit of work in your app.

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Tuesday, March 8, 2011 7:13 AM
    Moderator
  • This is a bit late but I ended up restructing my service:

    Seeing how i'm sharing my database layer among the clients....

     

    1.  I use stored procedures instead of the linq to SQL table objects for  CRUD operations.  Stored procedures are much faster than the LINQ to SQL table objects.

    2. Each client that comes in gets its own copy of some the stored procedure handles.   The shared storedprocedures variables i have in my database layer gets set to the incoming client copy of the stored procedures.    I have SyncLock objects as well.

    3. I broke up the database updates within the  transactions to more more transactions with less operations instead of less transactions and more operations.

     

     


    Rob Hermann
    • Marked as answer by 10437NiceGuy Tuesday, August 30, 2011 10:00 PM
    Tuesday, August 30, 2011 10:00 PM