Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Linq datacontext issue, Object not set to instance of an object

Linq datacontext issue, Object not set to instance of an object

Scheduled Pinned Locked Moved LINQ
helpcsharpdatabasedebuggingasp-net
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RB Emphasys
    wrote on last edited by
    #1

    Alright Guys, I have a truly hairy bug here. We have a asp.net app in which we use linq to access a sql2005 db. It was working great for several months. Just recently, from time to time, whenever we try to insert a entity object to the datacontext and then call submitchanges(), it throws an exception with the lovely old Object Not Set to Instance of an object. But it's only on insert, updates work great. If you look at the stack trace, it's throwing the error down in the change tracker. I thought maybe it was a bad row or entity object, but even running as simple test through the debugger will throw the error when no other entity objects have been loaded. The only way we've found to fix the issue, is to restore the db to the last backup we had. I thought that it was possible that we're loading bad data somewhere. But I pointed a previous version of the app, "pre-bug", to the same database that is currently causing issues, and it runs perfectly. Any idea's, comments, or suggestions would be greatly appreciated. Thanks again, Ryan

    H 1 Reply Last reply
    0
    • R RB Emphasys

      Alright Guys, I have a truly hairy bug here. We have a asp.net app in which we use linq to access a sql2005 db. It was working great for several months. Just recently, from time to time, whenever we try to insert a entity object to the datacontext and then call submitchanges(), it throws an exception with the lovely old Object Not Set to Instance of an object. But it's only on insert, updates work great. If you look at the stack trace, it's throwing the error down in the change tracker. I thought maybe it was a bad row or entity object, but even running as simple test through the debugger will throw the error when no other entity objects have been loaded. The only way we've found to fix the issue, is to restore the db to the last backup we had. I thought that it was possible that we're loading bad data somewhere. But I pointed a previous version of the app, "pre-bug", to the same database that is currently causing issues, and it runs perfectly. Any idea's, comments, or suggestions would be greatly appreciated. Thanks again, Ryan

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      The only thing i can think of is that a non-nullable field(s) was added to your table... Is this the case?

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

      R 1 Reply Last reply
      0
      • H Harvey Saayman

        The only thing i can think of is that a non-nullable field(s) was added to your table... Is this the case?

        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

        R Offline
        R Offline
        RB Emphasys
        wrote on last edited by
        #3

        Harvey, Thanks for the reply. It was actually something quite similiar. We were setting a datetime column of some of our entity classes to DateTime.MinValue. As you know, this is much lower than what the entity class would accept. The tricky part was, we were catching the error, logging it, and the app continued. The problem was, were were never clearing the datacontext, so anytime we tried to submitchanges(), the datacontext would run into that one bad entity class. Instead of just stating, the datetime value is less than allowed, it would throw a null reference exception and abort. We ended up fixing the issue two fold. We obviously created a static date that matched the entity lower bound date value. On top of this, we catch those submit change issues when they happen, log them, and clear the entity cache. This seems to have done the trick, thanks for the response. Ryan

        H 1 Reply Last reply
        0
        • R RB Emphasys

          Harvey, Thanks for the reply. It was actually something quite similiar. We were setting a datetime column of some of our entity classes to DateTime.MinValue. As you know, this is much lower than what the entity class would accept. The tricky part was, we were catching the error, logging it, and the app continued. The problem was, were were never clearing the datacontext, so anytime we tried to submitchanges(), the datacontext would run into that one bad entity class. Instead of just stating, the datetime value is less than allowed, it would throw a null reference exception and abort. We ended up fixing the issue two fold. We obviously created a static date that matched the entity lower bound date value. On top of this, we catch those submit change issues when they happen, log them, and clear the entity cache. This seems to have done the trick, thanks for the response. Ryan

          H Offline
          H Offline
          Harvey Saayman
          wrote on last edited by
          #4

          Your welcome I've had similar issues when not assigning a value to a NOT NULL DateTime field, and then i get some ambigious error message at ctx.SubmitChanges();... took forever to find it Glad you sorted your problem out

          Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups