473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Read from database as I do from web.config

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
Nov 19 '05 #1
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

Nov 19 '05 #2
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


Nov 19 '05 #3
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

Nov 19 '05 #4
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


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
4
by: Programmer | last post by:
Hi everyone Well here is my problem I hope you can help me
1
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...
7
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...
4
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...
4
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: ...
5
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...
4
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...
3
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...
0
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...
1
isladogs
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...
0
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...
0
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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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....
0
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
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.