none
C# to SQL fails after first successful call RRS feed

  • Question

  • I've been bashing up against this problem for a while now. I used Entity Framework Code First from an existing Database. I'm sending the requests to the database to get or set  or whatever a row and it always succeeds the first time, but if i try to run another query, on the same or another table it fails. Using Entity Framework or LINQ it returns null even though the values I'm trying to get/set exist. If I use sqlcommand and raw sql it throws a sqlexception "invalid object 'table'" where table is the name of the table in the database, with and without dbo. I get the same exception.

    Any help would be greatly appreciated.

    PS: the only way to get around this now it to restart the service making the requests.

    Friday, March 24, 2017 9:21 PM

Answers

  • Thanks Wendy and Cole, but I finally managed to sort it out on my own.

    The problem was that database was not being saved so it was fine on the first call when it had the database in the connection string but in subsequent calls it didn't and couldn't find the table so either errored out or returned empty results. I thought I checked the string but I guess I didn't do that well enough.

    • Marked as answer by Penny Over Monday, March 27, 2017 7:12 PM
    Monday, March 27, 2017 7:12 PM

All replies

  • Hi Penny Over,

    Thank you for posting here.

    According to your question is more related to EF, I will move it to ADO.NET Entity Framework and LINQ to Entities forum for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 27, 2017 2:14 AM
  • Hi Penny Over,

    Could you please provide related code or simple demo, which we could reproduce the issue on my side.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 27, 2017 8:32 AM
    Moderator
  • Thanks Wendy and Cole, but I finally managed to sort it out on my own.

    The problem was that database was not being saved so it was fine on the first call when it had the database in the connection string but in subsequent calls it didn't and couldn't find the table so either errored out or returned empty results. I thought I checked the string but I guess I didn't do that well enough.

    • Marked as answer by Penny Over Monday, March 27, 2017 7:12 PM
    Monday, March 27, 2017 7:12 PM