R
Rick
I have gotten my Custom MembershipProvider working with my own SQL Server DB.
The application authenticates a particular company with ValidateUser and I
want to then call up the Company record from my SQL Server DB. I need to
retrieve the Primary Key (CompanyID) from the DB and use that to open the
correct SqlDataSource. I need to figure out if it's possible to do this with
MemebershipUser without having to set up a Personalization Provider. It seems
like there are two options, one is to retrieve the CompanyID from
ValidateUser and stuff it into a Session Variable. The other would be to set
up GetUser to pull the CompanyID in as the ProviderUserKey. I presume its
better to use GetUser but I don't know how to write the GetUser code. Here's
my ValidateUser
Public Overrides Function ValidateUser(ByVal userName As String, ByVal
password As String) As Boolean
Dim boolReturn As Boolean = False
Dim connString As String
Dim CompanyID As Integer
connString = "Server=server;User ID=UID;password=pw;Database=db"
Dim commString As String
commString = "SELECT CompanyID from Company WHERE Userid =
@UserID and Password = @Password"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim cmd As SqlCommand = New SqlCommand(commString, conn)
cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = userName
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value =
password
' Open the connection and execute the reader
conn.Open()
Dim reader As SqlDataReader
reader = cmd.ExecuteReader()
' Did we find a user?
If reader.Read() Then
boolReturn = True
CompanyID = (reader("CompanyID"))
'CompanySession =
End If
' Close connections
reader.Close()
conn.Close()
cmd = Nothing
Return boolReturn
End Function
The application authenticates a particular company with ValidateUser and I
want to then call up the Company record from my SQL Server DB. I need to
retrieve the Primary Key (CompanyID) from the DB and use that to open the
correct SqlDataSource. I need to figure out if it's possible to do this with
MemebershipUser without having to set up a Personalization Provider. It seems
like there are two options, one is to retrieve the CompanyID from
ValidateUser and stuff it into a Session Variable. The other would be to set
up GetUser to pull the CompanyID in as the ProviderUserKey. I presume its
better to use GetUser but I don't know how to write the GetUser code. Here's
my ValidateUser
Public Overrides Function ValidateUser(ByVal userName As String, ByVal
password As String) As Boolean
Dim boolReturn As Boolean = False
Dim connString As String
Dim CompanyID As Integer
connString = "Server=server;User ID=UID;password=pw;Database=db"
Dim commString As String
commString = "SELECT CompanyID from Company WHERE Userid =
@UserID and Password = @Password"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim cmd As SqlCommand = New SqlCommand(commString, conn)
cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = userName
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value =
password
' Open the connection and execute the reader
conn.Open()
Dim reader As SqlDataReader
reader = cmd.ExecuteReader()
' Did we find a user?
If reader.Read() Then
boolReturn = True
CompanyID = (reader("CompanyID"))
'CompanySession =
End If
' Close connections
reader.Close()
conn.Close()
cmd = Nothing
Return boolReturn
End Function