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. Web Development
  3. ASP.NET
  4. Object reference not set and session issue...

Object reference not set and session issue...

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
3 Posts 2 Posters 1 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.
  • K Offline
    K Offline
    Kasic Slobodan
    wrote on last edited by
    #1

    I am sorry for stupid title, but I don't know how to name the thread. Anyway, I am working on a web admin panel and I have a problem about object reference. I know what this error mean, but what I don't know is why I reload some page 1000 times and I try to reload it 1001 time, and I get object reference? Sometimes is on if (dataReader.Read()) and sometimes on if ((bool)Session["SomeText"]). Can session be abandoned this way? Before this if's, I have another if (in session_start in global.asax) that verifies whether session is null or not. Does anyone have an idea what could be a problem?

    C 1 Reply Last reply
    0
    • K Kasic Slobodan

      I am sorry for stupid title, but I don't know how to name the thread. Anyway, I am working on a web admin panel and I have a problem about object reference. I know what this error mean, but what I don't know is why I reload some page 1000 times and I try to reload it 1001 time, and I get object reference? Sometimes is on if (dataReader.Read()) and sometimes on if ((bool)Session["SomeText"]). Can session be abandoned this way? Before this if's, I have another if (in session_start in global.asax) that verifies whether session is null or not. Does anyone have an idea what could be a problem?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I guess if your database connection fails, you get a dataReader back that is null, and you're not checking it. And, I guess your session must be timing out. I always check if a session variable is null before I try to convert it to anything. In fact, I'd tend to wrap it in a property that does exactly that, so it's written once and used every time.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      K 1 Reply Last reply
      0
      • C Christian Graus

        I guess if your database connection fails, you get a dataReader back that is null, and you're not checking it. And, I guess your session must be timing out. I always check if a session variable is null before I try to convert it to anything. In fact, I'd tend to wrap it in a property that does exactly that, so it's written once and used every time.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        K Offline
        K Offline
        Kasic Slobodan
        wrote on last edited by
        #3

        I've added check if connection is opened, but unfortunately, I have to wait to see if error comes again :), but I definitely have to change some things in my code. Your session property sounds great. I have to implement that. Thank you Christian and best regards.

        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