Object reference not set to an instance of an object -- Why??

W

Wayne P.

I'm getting said error on the line Do While reader.Read()

Looks like reader is defined to me.....so I'm lost....

This is for role based security, and this sub is in Global.asax if it makes
any difference.

Sub RoleAuthentication_RetrieveRoles(ByVal sender As Object, ByVal args As
RetrieveRolesArgs)
Dim RoleList As ArrayList
Dim reader As System.Data.SqlClient.SqlDataReader
reader = SqlHelper.ExecuteReader("Data
Source=""DEVPC\VSDOTNET"";database=web;user=webuser;password=test;",
CommandType.StoredProcedure, "Login", New SqlParameter("@username",
args.UserId))

Do While reader.Read()
RoleList.Add(reader("name"))
Loop

args.Roles = RoleList.ToArray(GetType(String))

End Sub

Thanks!
Wayne P.
 
W

Wayne P.

In query analyzer, i get results from my stored procedure.

When trying the hasrows, I get the same error -

It is as if my SqlDataReader object, reader, has forgotten what it is....

Wayne P.
 
M

Miha Markic [MVP C#]

Sounds to me like SqlHelper.ExecuteReader isn't returning a valid instance
or better it is returning null.
You might check into the method.
 
J

Jon Skeet [C# MVP]

Wayne P. said:
I'm getting said error on the line Do While reader.Read()

Looks like reader is defined to me.....so I'm lost....

This is for role based security, and this sub is in Global.asax if it makes
any difference.

Sub RoleAuthentication_RetrieveRoles(ByVal sender As Object, ByVal args As
RetrieveRolesArgs)
Dim RoleList As ArrayList
Dim reader As System.Data.SqlClient.SqlDataReader
reader = SqlHelper.ExecuteReader("Data
Source=""DEVPC\VSDOTNET"";database=web;user=webuser;password=test;",
CommandType.StoredProcedure, "Login", New SqlParameter("@username",
args.UserId))

Do While reader.Read()
RoleList.Add(reader("name"))
Loop

I think you're actually getting it on the following line. You've
declared RoleList as an ArrayList, but unless I'm mistaken about VB.NET
syntax, you haven't actually *created* a new ArrayList.
 
G

Grzegorz Danowski

U¿ytkownik "Wayne P. said:
I'm getting said error on the line Do While reader.Read()

Looks like reader is defined to me.....so I'm lost....

This is for role based security, and this sub is in Global.asax if it
makes
any difference.

Sub RoleAuthentication_RetrieveRoles(ByVal sender As Object, ByVal args As
RetrieveRolesArgs)
Dim RoleList As ArrayList

'Add:
RoleList = New ArrayList
(...)

Grzegorz
 
W

Wayne P.

Thanks, that very well is needed, but it did not solve my error.

I wish I could look into the method of SQLHelper, but that component is from
the MS Application Blocks (data access) routine....

I have a simular statement elsewhere in my code with SqlHelper, and it is
working. I guess it is time to use a different component in this section.

Perhaps it doesn't like being in the Global.asax file....why it wouldn't
doesn't make sense to me.

Thanks for everyones replies....I'll check back here to see if any other
comments have been posted but I need to move on past this error....

Wayne P.
 
O

Otis Mukinfus

Perhaps you didn't send all of your code, but if you did I see no
try/catch block in the code sample. This is the error you will
receive many times for an unhandled error.

If you don't have error handling already in the code, wrap it in a
try/catch block and put a breakpoint in the catch block. when the
execution stops at the breakpoint open up quickwatch and see what the
error description really is.

I'm getting said error on the line Do While reader.Read()

Looks like reader is defined to me.....so I'm lost....

This is for role based security, and this sub is in Global.asax if it makes
any difference.

Sub RoleAuthentication_RetrieveRoles(ByVal sender As Object, ByVal args As
RetrieveRolesArgs)
Dim RoleList As ArrayList
Dim reader As System.Data.SqlClient.SqlDataReader
reader = SqlHelper.ExecuteReader("Data
Source=""DEVPC\VSDOTNET"";database=web;user=webuser;password=test;",
CommandType.StoredProcedure, "Login", New SqlParameter("@username",
args.UserId))

Do While reader.Read()
RoleList.Add(reader("name"))
Loop

args.Roles = RoleList.ToArray(GetType(String))

End Sub

Thanks!
Wayne P.

Otis Mukinfus
http://www.otismukinfus.com
 
L

Ligeyi

There are two things you need to do:

First, I think this is a scope issue. Try and declare the line : Dim
RoleList As ArrayList outside your sub procedure.

Finally, confirm that the stored procedure you are using - Login - returns
a value(s) with the field name 'name'. Use your database software to verify
this.

I hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top