When I try to use a value stored in the Profile in a public class I receive the following error message.
?currentProfile.DBServerIP
15string
A first chance exception of type 'System.Configuration.Sett
ingsProper
tyNotFound
Exception'
occurred in System.dll
Previously I asked how to access the Profile values in a public class. It was answered. That solution had me add.
Dim currentProfile as new ProfileCommon to each of the subroutines in the public class.
It is working. There is a subroutine which assigns the values to all of the properties in my Profile. This works fine.
It is later after opening several other pages that the problem occurs. When the page Load event fires the Profile.DBServerIP15String
does contain a value. The next line in the page load event calls the Public class. I dimensioned the variable currentProfile just as I did earlier when I assigned values to my Profile. But this second time is when I get the error.
What am I doing wrong?
The Profile variables are defined in the web.config and stored in Sql 2005.
Page Load event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
'AT THIS POINT PROFILE.DBSERVERIP15STRING
CONTAINS A VALUE
LogInCtl.PopulateStateDrop
DownList(M
e.StateDro
pDownList1
)
DataCtl.PopulateCountryCod
es(Me.Coun
tryDropDow
nList1)
LoadAdminInfo()
Else
End If
End Sub
The subroutine in the Public Class LOGINCTL
Public Shared Sub PopulateStateDropDownList(
ByRef objDDL As DropDownList)
Dim AdminConnSqlConnection As New System.Data.SqlClient.SqlC
onnection
Dim Dr1SqlDataReader As System.Data.SqlClient.SqlD
ataReader
Dim Dr1SqlCommand As New System.Data.SqlClient.SqlC
ommand
Dim Parmstring As String
Dim strStateCode As String
Dim strStateName As String
Dim currentProfile As New ProfileCommon
'AT THIS POINT currentProfile.DBServerIP1
5String HAS NOT BEEN ASSIGNED A VALUE. WHY?????
Parmstring = "Server=" & currentProfile.DBServerIP1
5string.Tr
im & "\" & currentProfile.ServerSqlIn
stanceName
20string & _
"; Database=Admin01; User ID=" & currentProfile.DBUserName1
5string.Tr
im & "; Password=" & currentProfile.DBPassword1
5string.Tr
im
end sub