Object reference not set and session issue...
-
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?
-
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?
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 )
-
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 )
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.