DataReader Problem

G

Guest

Can someone tell my why my DataReader doesn't read and create the array???

I think it is something to do with the reader = cmd.ExecuteReader line but
I'm not sure what it be!

Thanks


If Request.IsAuthenticated Then

Dim objConn
Dim cmd As OleDbCommand
Dim strSQL As String

strSQL = "SELECT GroupAccess FROM person where personNo =
@Username"

objConn = New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
cmd = New OleDbCommand(strSQL, objConn)

'Determine this user's roles
Dim reader As OleDbDataReader
cmd.Parameters.Add("@Username", User.Identity.Name)
objConn.Open()
reader = cmd.ExecuteReader


' Create an array of role names
Dim roleList As New ArrayList
Do While reader.Read
roleList.Add(reader("GroupAccess"))
Loop
reader.Close()

'Convert the roleList ArrayList to a String array
Dim roleListArray As String() = roleList.ToArray(GetType(String))

'Add the roles to the User Principal
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(User.Identity, roleListArray)


End If
 
M

Marina Levit [MVP]

Your access code looks fine.

What is the value of User.Identity.Name - is it what you expect? Is it empty
string? It is possible that this is not the right value, and so nothing is
being retrieved.

Have you traced through this one line at a time? Do any rows come back at
all?

As an aside, you never close the connection in this code snippet. This
whole thing needs to be in a try/finally block that cleans everything up or
in a Using block.
 
G

Guest

The user.Identity.Name looks fine when I run the debug... ooopppsss no it
doesn't!

Thanks!

Pulling the wrong thing from the db!
 
G

Guest

Just one more quick question???

How do I redirect to another page if the Request.IsAuthenticated is False
and it is the second time it is false???

IE: When you load the page you get the normal page! But if you try again you
get another page!

I tried Response.Redirect but that means you get redirected as soon as the
default.aspx loads...

Thanks again!
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top