Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 Custom Profile Provider ASP.NET 2.0
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

kentk
Starting Member

USA
30 Posts

Posted - 08 June 2006 :  11:29:02  Show Profile
I am creating a custom profile provider, the provider inherits from the profileProvider class. In the below function there is a context object, I use the context("User_Name") to create my sql parameter. If I set a breakpoint on the line ".Parameters.AddWithValue("@M_NAME", context("User_Name"))" the context("User_Name") will have a value, the value of my login name when it hits the breakpoint. If I step to the next line it "seems" to lose it value. Is it some kinda timing issue or something else I'm not setting?

Any help would be greatly appreciated.

Thanks


Public Overrides Function GetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal collection As System.Configuration.SettingsPropertyCollection) As System.Configuration.SettingsPropertyValueCollection
Dim values As New SettingsPropertyValueCollection
Dim conn As New SqlConnection(connStr)
Dim strSQL As String = "SELECT * FROM FORUM_MEMBERS WHERE M_NAME = @M_NAME"
Dim cmd As SqlCommand
Dim setProperty As SettingsProperty
Dim reader As SqlDataReader

Try
cmd = New SqlCommand(strsql, conn)

With cmd
.CommandType = Data.CommandType.Text
.Parameters.AddWithValue("@M_NAME", context("User_Name"))

conn.Open()

reader = .ExecuteReader(Data.CommandBehavior.SingleRow)

End With

For Each setProperty In collection
Dim setValue As New SettingsPropertyValue(setProperty)
If reader.HasRows Then
setValue.PropertyValue = reader(setProperty.Name)
values.Add(setValue)
End If

Next

Return values
Catch ex As Exception
Throw ex
Finally
conn.Close()
cmd.Dispose()
End Try
End Function

Kent

"Wakey, wakey, hands off snakey!"

kentk
Starting Member

USA
30 Posts

Posted - 08 June 2006 :  13:16:30  Show Profile
Solved my own problem,

context("User_Name") should be context("UserName")

Function should look like this:
Public Overrides Function GetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal collection As System.Configuration.SettingsPropertyCollection) As System.Configuration.SettingsPropertyValueCollection
Dim values As New SettingsPropertyValueCollection
Dim conn As New SqlConnection(connStr)
Dim strSQL As String = "SELECT * FROM FORUM_MEMBERS WHERE M_NAME = @M_NAME"
Dim cmd As SqlCommand
Dim setProperty As SettingsProperty
Dim reader As SqlDataReader

Try
cmd = New SqlCommand(strsql, conn)

With cmd
.CommandType = Data.CommandType.Text
.Parameters.AddWithValue("@M_NAME", CType(context("UserName"), String))

conn.Open()

reader = .ExecuteReader(Data.CommandBehavior.SingleRow)

End With
If reader.HasRows Then
reader.Read()

For Each setProperty In collection
Dim setValue As New SettingsPropertyValue(setProperty)
setValue.PropertyValue = reader(setProperty.Name)
values.Add(setValue)
Next
End If

Return values
Catch ex As Exception
Throw ex
Finally
conn.Close()
cmd.Dispose()
End Try
End Function

Kent

"Wakey, wakey, hands off snakey!"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000 Version 3.4.07