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.getconf ig()? 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.GetConf ig("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.SoftwareRequirem ents 'calling the
web.config & works great.
Dim softReqViewFromSQL As Object =
SoftwareRequirementsConfigSection.getFromSQLInstea dOfWebConfigTest '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 4 1785
You cannot because the framework itself loads the config when the app domain
starts. You cannot load it from a different location.
The object returned by GetConfig is dependent on the configuration handler
that is parsing the web.config XML. The reason for GetConfig is that you
can have an arbitrary XML structure in the config file that gets processed
and wrapped by some handler. That is why GetConfig returns an Object type.
"brent" <br***@newsgroup.nospam> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl... 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.getconf ig()? 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.GetConf ig("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.SoftwareRequirem ents 'calling the web.config & works great. Dim softReqViewFromSQL As Object = SoftwareRequirementsConfigSection.getFromSQLInstea dOfWebConfigTest
'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
Okay - now I know why it wasn't working! Thanks Peter.
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl... You cannot because the framework itself loads the config when the app domain starts. You cannot load it from a different location.
The object returned by GetConfig is dependent on the configuration handler that is parsing the web.config XML. The reason for GetConfig is that you can have an arbitrary XML structure in the config file that gets processed and wrapped by some handler. That is why GetConfig returns an Object type.
"brent" <br***@newsgroup.nospam> wrote in message news:u6**************@TK2MSFTNGP10.phx.gbl... 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.getconf ig()? 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.GetConf ig("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.SoftwareRequirem ents 'calling the web.config & works great. Dim softReqViewFromSQL As Object = SoftwareRequirementsConfigSection.getFromSQLInstea dOfWebConfigTest '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
If you're reading a set of name=value pairs from a database, why does it
have to be XML? Create a table, put 2 columns in it, one for name, and one
for value. Pull the table, and use the records in it. No need for XML.
A configuration file is, by definition, an XML file. This is the way these
files were created. However, all they do is store data, just like a
database. An XML file is a good database, but unless you need to translate
the data into some form of cross-platform-compatible data source (like XML)
there's no need to use XML IN your database.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"brent" <br***@newsgroup.nospam> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl... 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.getconf ig()? 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.GetConf ig("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.SoftwareRequirem ents 'calling the web.config & works great. Dim softReqViewFromSQL As Object = SoftwareRequirementsConfigSection.getFromSQLInstea dOfWebConfigTest '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
It does. Thanks, Kevin.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl... If you're reading a set of name=value pairs from a database, why does it have to be XML? Create a table, put 2 columns in it, one for name, and one for value. Pull the table, and use the records in it. No need for XML.
A configuration file is, by definition, an XML file. This is the way these files were created. However, all they do is store data, just like a database. An XML file is a good database, but unless you need to translate the data into some form of cross-platform-compatible data source (like XML) there's no need to use XML IN your database.
-- HTH,
Kevin Spencer Microsoft MVP .Net Developer Neither a follower nor a lender be.
"brent" <br***@newsgroup.nospam> wrote in message news:u6**************@TK2MSFTNGP10.phx.gbl... 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.getconf ig()? 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.GetConf ig("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.SoftwareRequirem ents 'calling the web.config & works great. Dim softReqViewFromSQL As Object = SoftwareRequirementsConfigSection.getFromSQLInstea dOfWebConfigTest '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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Silvio Lopes de Oliveira |
last post by:
Hello,
I have a C++ / MFC app which uses CDatabase and CRecordset to connect to a
ODBC data source for a SQL Server 7 database. The application worked
properly with a MySQL database, but after...
|
by: Programmer |
last post by:
Hi everyone
Well here is my problem
I hope you can help me
|
by: Dan Noel |
last post by:
I see many rich classes in System.Configuration, but all of these classes
are read-only.
While I have many rich classes for extracting information from a config
while, I am reduced to the most...
|
by: Bob |
last post by:
It's great that VS.NET makes it so effortless to add a web reference to a
web service. The problem is, I haven't figured out a way to configure the
URLs (or simply switch the references to another...
|
by: Miro |
last post by:
Hello!
I have an ASP.NET application which needs to read some data from an Access
database on Novell. I've found an article on Microsoft and did the following:
I've created an account on...
|
by: Steve Enzer |
last post by:
I need to use a configuration file to set the connection string for the ado
data connector in my project, but I'm having trouble reading the config
file.
My config file contains the following:
...
|
by: Sridhar |
last post by:
Hi,
I have created a project which contains classes to read the data from the
database. This project has an App.Config file which contains the
SqlConnection String. when this code is called from...
|
by: klynn |
last post by:
Hi:
I'm having problems reading a Microsoft Access file from my ASP.Net app on a
Windows Server 2003 machine. The error message:
The Microsoft database engine cannot open the file, <my_file>. It...
|
by: josh.kuo |
last post by:
Sorry about the subject, I can't think of a better one.
I recently wrote some PHP classes that I think might be of interest to
this group. Since I have been reaping the benefits of reading news...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |