GUID = empty?

Topics: Data Access Application Block
Jul 30, 2008 at 9:26 AM
Edited Jul 30, 2008 at 9:30 AM

I'm attempting to write a custom membership provider that uses the DAAB. Everything is running brilliantly but there is this one (rahter serious) problem.

It's apparently impossible to get the GUID (that I can clearly see in the database) out of it using the DAAB. Is there a known issue with this? I'm using Microsoft SQL Server Standard Edition (64-bit) / 9.00.3054.00 and the 3.1 DAAB.

I have tried reader.GetValue(0) (it's the first column), reader.GetGuid(0), ... I also tried adding an OutParameter of the GUID type but I might have done that wrong.

The pkid column is a primary key of the type 'uniqueidentifier'. And I tried it with putting RowGuid to yes and no.

All the following belongs to the same class:

       Private fields As String = "pkid, username, email, password_question," & _
                         " comment, is_approved, is_locked, created_at, last_login_date," & _
                         " last_activity_date, last_password_change_date, last_locked_date"

       Public Overrides Function GetUser(ByVal username As String, ByVal userIsOnline As Boolean) As MembershipUser
            Dim u As MembershipUser = Nothing

            Using cmd As Data.Common.DbCommand = dataBase.GetSqlStringCommand("SELECT " & fields & _
                " FROM Users WHERE username = @username AND application_name = @application_name")
                dataBase.AddInParameter(cmd, "@username", DbType.String, username)
                dataBase.AddInParameter(cmd, "@application_name", DbType.String, ApplicationName)

                    Using reader As Data.IDataReader = dataBase.ExecuteReader(cmd)
                        While reader.Read()
                            u = GetUserFromReader(reader)

                            If userIsOnline Then
                                Using cmd_update As Data.Common.DbCommand = dataBase.GetSqlStringCommand("UPDATE Users SET last_activity_date = @LastActivityDate WHERE username = @username AND application_name = @application_name")
                                    dataBase.AddInParameter(cmd_update, "@LastActivityDate", DbType.DateTime, DateTime.Now)
                                    dataBase.AddInParameter(cmd_update, "@username", DbType.String, username)
                                    dataBase.AddInParameter(cmd_update, "@application_name", DbType.String, ApplicationName)

                                End Using
                            End If
                        End While
                    End Using
                Catch ex As Exception
                    If Not IsNothing(ex) Then
                        If WriteExceptionsToLog Then
                            WriteToLog(ex, "GetUser(String, Boolean)")

                            Throw New ProviderException(exceptionMessage)
                            Throw ex
                        End If
                    End If
                End Try
            End Using

            Return u
        End Function

        Private Function GetUserFromReader(ByVal reader As Data.IDataReader) As MembershipUser
            Dim providerUserKey As Guid = reader.GetGuid(0) ' <----------- fails :( Always returns an Empty GUID.
            Dim username As String = reader.GetString(1)
            Dim email As String = reader.GetString(2)

            Dim passwordQuestion As String = ""
            If Not reader.GetValue(3) Is DBNull.Value Then _
              passwordQuestion = reader.GetString(3)

            Dim comment As String = ""
            If Not reader.GetValue(4) Is DBNull.Value Then _
              comment = reader.GetString(4)

            Dim isApproved As Boolean = reader.GetBoolean(5)
            Dim isLockedOut As Boolean = reader.GetBoolean(6)
            Dim creationDate As DateTime = reader.GetDateTime(7)

            Dim lastLoginDate As DateTime = New DateTime()
            If Not reader.GetValue(8) Is DBNull.Value Then _
              lastLoginDate = reader.GetDateTime(8)

            Dim lastActivityDate As DateTime = reader.GetDateTime(9)
            Dim lastPasswordChangedDate As DateTime = reader.GetDateTime(10)

            Dim lastLockedOutDate As DateTime = New DateTime()
            If Not reader.GetValue(11) Is DBNull.Value Then _
              lastLockedOutDate = reader.GetDateTime(11)

            Dim u As MembershipUser = New MembershipUser(Me.Name, username, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockedOutDate)

            Return u
        End Function

Any help is appreciated.
Jul 30, 2008 at 1:06 PM
lol .. turns out my wonderful logic is more logical than the .NET logic. Apparently a non-empty GUID is labeled as Empty. I get it ... haha ... very funny microsoft. *sigh*. Anyway, glad I getit now lol :D

In other words this can be deleted/closed.