Friday, March 16, 2012

Object reference not set to an instance of an object.

Hello could someone please help me with this error?
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

<code>
Line 99: Else
Line 100: '####################
Line 101: Dim objCommand As OdbcCommand = New OdbcCommand("SELECT AuthKey FROM online_user WHERE Username='" & HttpContext.Current.Session("usr_Username").ToString() & "'", objConnection)
Line 102:
Line 103: objConnection.Open()
</code>


Thanks in adavnce

Hello,
The error is in this line HttpContext.Current.Session("usr_Username").ToString()
If the session is empty you will get that type of error. You can solve this problem by removing tostring method to be like this
HttpContext.Current.Session("usr_Username")

HTH
regards
Thanks smiling4ever,
The Session object was indeed empty.

0 comments:

Post a Comment