B
brent
Currently our application is reading from the web.config, and retrieves a
section, "softwareRequirements". Because the section will begin to grow
dramatically, I'd like to place it in the SQL database instead. I've
imported the values, and am retrieving them as FOR XML AUTO in the stored
proc to mimic the structure in the web.config. I'm confused now - what data
type is being returned by
system.configuration.configurationsettings.getconfig()? It looks like it has
to be an array or xml, but I'm not experienced enough at .NET to determine
how to best handle it. I would like to just provide a different data source
and leave the rest of my code the same.
Current code to read web.config:
Public Shared Function SoftwareRequirements() As
SoftwareRequirementsView
Return
System.Configuration.ConfigurationSettings.GetConfig("softwareRequirements")
End Function
<Serializable()> _
Public Class SoftwareRequirementView
Inherits UserProvisioningData.SoftwareRequirement
Private _ctrlId As String
Public Sub New(ByVal name As String, ByVal value As String, ByVal prompt
As String, ByVal availableTo As String)
MyBase.New(name, value, prompt, availableTo)
End Sub
Public Property ControlId() As String
Get
Return _ctrlId
End Get
Set(ByVal Value As String)
_ctrlId = Value
End Set
End Property
Public ReadOnly Property AdditionalRequirement(ByVal name As String) As
ItemDetail
Get
Dim result As ItemDetail
For Each req As ItemDetail In MyBase.AdditionalRequirements
If req.Name = name Then
result = req
Exit For
End If
Next
Return result
End Get
End Property
End Class
I'm attempting to pass data in from SQL instead:
Public Function GetSoftwareConfiguration(ByVal divisionId As Integer,
ByVal brandId As Integer, ByVal operationId As Integer, ByVal branchId As
Integer) As ArrayList
Dim methodPerf As New FNF.Services.Common.PerfAutoTrace
Dim result As ArrayList =
DBCommon.GetDataArray(GetType(UserProvisioningData.SoftwareRequirement),
DBCommon.ConnectionString("myDB"), "get_SoftwareConfig", New Object()
{divisionId, brandId, operationId, branchId})
methodPerf.Dispose()
Return result
End Function
Public Shared Function GetDataArray(ByVal returnType As Type, ByVal
connectionString As String, ByVal storedProcName As String, Optional ByVal
params() As Object = Nothing) As Object
Dim reader As SqlDataReader
Dim result As New ArrayList
Try
reader = SqlHelper.ExecuteReader(connectionString,
storedProcName, params)
While (reader.Read)
Dim item As Object = returnType.InvokeMember("New",
Reflection.BindingFlags.CreateInstance, Nothing, Nothing, New Object()
{reader})
result.Add(item)
End While
Catch ex As FNFException
Throw
Catch ex As Exception
Dim newEx As New FNFException("Error getting data from
database", New Object() {connectionString, storedProcName}, ex)
ExceptionManager.Publish(newEx)
Throw newEx
Finally
If Not (reader Is Nothing) Then reader.Close()
End Try
Return result
End Function
Public Shared Function getFromSQLInsteadOfWebConfigTest() As Object
Dim data As UserProvisioningData.DataRequest
Return data.GetSoftwareConfiguration(1, 1, 1, 1)
End Function
When I try to load the page I get an exception when calling my
Dim softReqView As Object =
SoftwareRequirementsConfigSection.SoftwareRequirements 'calling the
web.config & works great.
Dim softReqViewFromSQL As Object =
SoftwareRequirementsConfigSection.getFromSQLInsteadOfWebConfigTest 'calling
sql and throws exception
Exception is:
Exception Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Any help would be appreciated.
Thanks,
Brent
section, "softwareRequirements". Because the section will begin to grow
dramatically, I'd like to place it in the SQL database instead. I've
imported the values, and am retrieving them as FOR XML AUTO in the stored
proc to mimic the structure in the web.config. I'm confused now - what data
type is being returned by
system.configuration.configurationsettings.getconfig()? It looks like it has
to be an array or xml, but I'm not experienced enough at .NET to determine
how to best handle it. I would like to just provide a different data source
and leave the rest of my code the same.
Current code to read web.config:
Public Shared Function SoftwareRequirements() As
SoftwareRequirementsView
Return
System.Configuration.ConfigurationSettings.GetConfig("softwareRequirements")
End Function
<Serializable()> _
Public Class SoftwareRequirementView
Inherits UserProvisioningData.SoftwareRequirement
Private _ctrlId As String
Public Sub New(ByVal name As String, ByVal value As String, ByVal prompt
As String, ByVal availableTo As String)
MyBase.New(name, value, prompt, availableTo)
End Sub
Public Property ControlId() As String
Get
Return _ctrlId
End Get
Set(ByVal Value As String)
_ctrlId = Value
End Set
End Property
Public ReadOnly Property AdditionalRequirement(ByVal name As String) As
ItemDetail
Get
Dim result As ItemDetail
For Each req As ItemDetail In MyBase.AdditionalRequirements
If req.Name = name Then
result = req
Exit For
End If
Next
Return result
End Get
End Property
End Class
I'm attempting to pass data in from SQL instead:
Public Function GetSoftwareConfiguration(ByVal divisionId As Integer,
ByVal brandId As Integer, ByVal operationId As Integer, ByVal branchId As
Integer) As ArrayList
Dim methodPerf As New FNF.Services.Common.PerfAutoTrace
Dim result As ArrayList =
DBCommon.GetDataArray(GetType(UserProvisioningData.SoftwareRequirement),
DBCommon.ConnectionString("myDB"), "get_SoftwareConfig", New Object()
{divisionId, brandId, operationId, branchId})
methodPerf.Dispose()
Return result
End Function
Public Shared Function GetDataArray(ByVal returnType As Type, ByVal
connectionString As String, ByVal storedProcName As String, Optional ByVal
params() As Object = Nothing) As Object
Dim reader As SqlDataReader
Dim result As New ArrayList
Try
reader = SqlHelper.ExecuteReader(connectionString,
storedProcName, params)
While (reader.Read)
Dim item As Object = returnType.InvokeMember("New",
Reflection.BindingFlags.CreateInstance, Nothing, Nothing, New Object()
{reader})
result.Add(item)
End While
Catch ex As FNFException
Throw
Catch ex As Exception
Dim newEx As New FNFException("Error getting data from
database", New Object() {connectionString, storedProcName}, ex)
ExceptionManager.Publish(newEx)
Throw newEx
Finally
If Not (reader Is Nothing) Then reader.Close()
End Try
Return result
End Function
Public Shared Function getFromSQLInsteadOfWebConfigTest() As Object
Dim data As UserProvisioningData.DataRequest
Return data.GetSoftwareConfiguration(1, 1, 1, 1)
End Function
When I try to load the page I get an exception when calling my
Dim softReqView As Object =
SoftwareRequirementsConfigSection.SoftwareRequirements 'calling the
web.config & works great.
Dim softReqViewFromSQL As Object =
SoftwareRequirementsConfigSection.getFromSQLInsteadOfWebConfigTest 'calling
sql and throws exception
Exception is:
Exception Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Any help would be appreciated.
Thanks,
Brent