none
R/W and R/R concurrency RRS feed

  • Question

  • Hello, 

    I'm working on a personal software, where a virtual list is displayed, each item is loaded asynchronously because of the time it can take to parse it (like parsing emails for example). 

    My data layer is set of handcoded classes which use linq to sql queries to retrieve data from a sql server express 2008 database. Randomly I get the following error:

    Resetting the connection results in a different state than the initial login. The login fails.

    I don't perform specific customization of the database, I don't have stored procedures, just tables, links... 

    The web has 3 occurences of this message, but no useful answer.

    Could you help me with it ?

    Thank you in advance... and sorry for my bad english...

     

    • Moved by Bob Beauchemin Monday, August 1, 2011 5:48 AM Moved to a more relevent forum. Not sure if you're using EF or LINQ to SQL (From:.NET Framework inside SQL Server)
    Sunday, July 31, 2011 11:26 PM

Answers

All replies

  • you should use new DataContext instance for each operation(add,update,delete), don't forget use Using()


    I am fish.
    Wednesday, August 3, 2011 6:56 AM
  • you should use new DataContext instance for each operation(add,update,delete), don't forget use Using()


    I am fish.


    Is it a workaround or a recommandation in all cases ? I'm asking this because the typed datacontext generated by Visual Studio does not look like a lightweight object... 

    Yesterday, opening the connection manually after DataContext initialization prevented it to switch all time between Open/Closed states, but one break makes the state unstable again. So if you tell me using a new DataContext for each linq query is a good practice, I think I will adopt your solution.

     

     

    Wednesday, August 3, 2011 8:49 AM
  • Any update? Would you mind letting us know how it goes now?

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 4, 2011 10:45 AM
  • Hi,

    After my post, I've made other searches, and I found the following article:

    http://www.west-wind.com/weblog/posts/2008/Feb/05/Linq-to-SQL-DataContext-Lifetime-Management

     

    Looks like the approach of a DataContext created for every query may lead to another errors, so I've adopted the independant call to Open().

    The drawback is that an exception raised in a linq query is able to change the state of my connection, so it's a bit harder to make it all safe.

     

    Anyway, thank you for your answer Fly_fish.

    Tuesday, August 9, 2011 9:27 AM