469,927 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

reading dataconfiguration.config

Hi

After conducting a several searches, I wasn't sure where to post this
question. So my apologiesbefore hand for double posting this and possibly
posting to the wrong forum(s).

Okay, I have any application that uses the data access application building
block from Microsoft's Enterprise Library (patterns and practices site). I
want to allow the users to select the database connection. To do this, I
thought I could read the dataconfiguration.config file and obtain the name
attribute nodes from all the connectionString element nodes in the file.
Problem is, I can't get to them. This may be due to a lack of experience
and knowledge using XPath. I've tried a host of different XPath query
strings but I never get back more than one node and usually get zero nodes
when I should have two nodes.

Here is my dataconfiguration.config file (relatively short).

<?xml version="1.0" encoding="utf-8"?>

<dataConfiguration>

<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null">

<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
defaultInstance="s09\Magic.prod"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">

<databaseTypes>

<databaseType name="Sql Server"
type="Microsoft.Practices.EnterpriseLibrary.Data.S ql.SqlDatabase,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" />

</databaseTypes>

<instances>

<instance name="s11\eleven.prod" type="Sql Server"
connectionString="s11\eleven.prod" />

<instance name="s09\Magic.prod" type="Sql Server"
connectionString="s09\Magic.prod" />

</instances>

<connectionStrings>

<connectionString name="s11\eleven.prod">

<parameters>

<parameter name="database" value="jt1" isSensitive="false" />

<parameter name="Integrated Security" value="True" isSensitive="false" />

<parameter name="Max Pool Size" value="50" isSensitive="false" />

<parameter name="Min Pool Size" value="0" isSensitive="false" />

<parameter name="Connection Lifetime" value="30" isSensitive="false" />

<parameter name="Pooling" value="True" isSensitive="false" />

<parameter name="server" value="admsitsdbs11\eleven" isSensitive="false" />

</parameters>

</connectionString>

<connectionString name="s09\Magic.prod">

<parameters>

<parameter name="Connection Lifetime" value="30" isSensitive="false" />

<parameter name="database" value="s1" isSensitive="false" />

<parameter name="Integrated Security" value="True" isSensitive="false" />

<parameter name="Max Pool Size" value="5" isSensitive="false" />

<parameter name="Min Pool Size" value="0" isSensitive="false" />

<parameter name="Pooling" value="True" isSensitive="false" />

<parameter name="server" value="admsitsdbs09\magic" isSensitive="false" />

</parameters>

</connectionString>

</connectionStrings>

</enterpriseLibrary.databaseSettings>

</xmlSerializerSection>

</dataConfiguration>
Ok, and here is the code I'm trying to get to work. I've included commented
out XPath strings I've tried, which didn't work.

Dim filename As String

Dim ds As DataSet

Dim dt As DataTable

Dim row As DataRow

Dim config As XmlDataDocument

Dim node As XmlNode

Dim nodeList As XmlNodeList

Dim element As XmlElement

Dim nodePath As String

Try

filename = Application.StartupPath + "\" + "dataconfiguration.config"

ds = New DataSet

'ds.ReadXmlSchema(filename)

ds.ReadXml(filename)

config = New XmlDataDocument(ds)

'config.Load(filename)

'nodePath =
"//dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath =
"/dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath =
"dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath = "/dataConfiguration/xmlSerializerSection/*/connectionStrings"

'nodePath = "/*/*/*/connectionStrings"

'nodePath =
"descendant::dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings"

'nodePath =
"descendant::xmlSerializerSection/enterpriseLibrary.databaseSettings"

'nodePath = "//connectionString"

nodePath = "/dataConfiguration/xmlSerializerSection/*/connectionStrings"

nodeList = config.SelectNodes(nodePath)

'nodeList =
config.ChildNodes(0).ChildNodes(0).ChildNodes(0).S electNodes("//connectionStrings")

Catch ex As Exception

Throw ex

End Try

Any advice you can offer is appreciated! Thanks in advance!

JB
Nov 21 '05 #1
2 4932
This problem has been resolved. I received guidance in the
microsoft.public.dotnet.xml forum. Thanks

JB
"news.microsoft.com" <no****************@kc.rr.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

After conducting a several searches, I wasn't sure where to post this
question. So my apologiesbefore hand for double posting this and possibly
posting to the wrong forum(s).

Okay, I have any application that uses the data access application
building block from Microsoft's Enterprise Library (patterns and practices
site). I want to allow the users to select the database connection. To
do this, I thought I could read the dataconfiguration.config file and
obtain the name attribute nodes from all the connectionString element
nodes in the file. Problem is, I can't get to them. This may be due to a
lack of experience and knowledge using XPath. I've tried a host of
different XPath query strings but I never get back more than one node and
usually get zero nodes when I should have two nodes.

Here is my dataconfiguration.config file (relatively short).

<?xml version="1.0" encoding="utf-8"?>

<dataConfiguration>

<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null">

<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
defaultInstance="s09\Magic.prod"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">

<databaseTypes>

<databaseType name="Sql Server"
type="Microsoft.Practices.EnterpriseLibrary.Data.S ql.SqlDatabase,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" />

</databaseTypes>

<instances>

<instance name="s11\eleven.prod" type="Sql Server"
connectionString="s11\eleven.prod" />

<instance name="s09\Magic.prod" type="Sql Server"
connectionString="s09\Magic.prod" />

</instances>

<connectionStrings>

<connectionString name="s11\eleven.prod">

<parameters>

<parameter name="database" value="jt1" isSensitive="false" />

<parameter name="Integrated Security" value="True" isSensitive="false" />

<parameter name="Max Pool Size" value="50" isSensitive="false" />

<parameter name="Min Pool Size" value="0" isSensitive="false" />

<parameter name="Connection Lifetime" value="30" isSensitive="false" />

<parameter name="Pooling" value="True" isSensitive="false" />

<parameter name="server" value="admsitsdbs11\eleven" isSensitive="false"
/>

</parameters>

</connectionString>

<connectionString name="s09\Magic.prod">

<parameters>

<parameter name="Connection Lifetime" value="30" isSensitive="false" />

<parameter name="database" value="s1" isSensitive="false" />

<parameter name="Integrated Security" value="True" isSensitive="false" />

<parameter name="Max Pool Size" value="5" isSensitive="false" />

<parameter name="Min Pool Size" value="0" isSensitive="false" />

<parameter name="Pooling" value="True" isSensitive="false" />

<parameter name="server" value="admsitsdbs09\magic" isSensitive="false" />

</parameters>

</connectionString>

</connectionStrings>

</enterpriseLibrary.databaseSettings>

</xmlSerializerSection>

</dataConfiguration>
Ok, and here is the code I'm trying to get to work. I've included
commented out XPath strings I've tried, which didn't work.

Dim filename As String

Dim ds As DataSet

Dim dt As DataTable

Dim row As DataRow

Dim config As XmlDataDocument

Dim node As XmlNode

Dim nodeList As XmlNodeList

Dim element As XmlElement

Dim nodePath As String

Try

filename = Application.StartupPath + "\" + "dataconfiguration.config"

ds = New DataSet

'ds.ReadXmlSchema(filename)

ds.ReadXml(filename)

config = New XmlDataDocument(ds)

'config.Load(filename)

'nodePath =
"//dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath =
"/dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath =
"dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath = "/dataConfiguration/xmlSerializerSection/*/connectionStrings"

'nodePath = "/*/*/*/connectionStrings"

'nodePath =
"descendant::dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings"

'nodePath =
"descendant::xmlSerializerSection/enterpriseLibrary.databaseSettings"

'nodePath = "//connectionString"

nodePath = "/dataConfiguration/xmlSerializerSection/*/connectionStrings"

nodeList = config.SelectNodes(nodePath)

'nodeList =
config.ChildNodes(0).ChildNodes(0).ChildNodes(0).S electNodes("//connectionStrings")

Catch ex As Exception

Throw ex

End Try

Any advice you can offer is appreciated! Thanks in advance!

JB

Nov 21 '05 #2
This problem has been resolved. I received guidance in the
microsoft.public.dotnet.xml forum. Thanks

JB

"news.microsoft.com" <no****************@kc.rr.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

After conducting a several searches, I wasn't sure where to post this
question. So my apologiesbefore hand for double posting this and possibly
posting to the wrong forum(s).

Okay, I have any application that uses the data access application
building block from Microsoft's Enterprise Library (patterns and practices
site). I want to allow the users to select the database connection. To
do this, I thought I could read the dataconfiguration.config file and
obtain the name attribute nodes from all the connectionString element
nodes in the file. Problem is, I can't get to them. This may be due to a
lack of experience and knowledge using XPath. I've tried a host of
different XPath query strings but I never get back more than one node and
usually get zero nodes when I should have two nodes.

Here is my dataconfiguration.config file (relatively short).

<?xml version="1.0" encoding="utf-8"?>

<dataConfiguration>

<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null">

<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
defaultInstance="s09\Magic.prod"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">

<databaseTypes>

<databaseType name="Sql Server"
type="Microsoft.Practices.EnterpriseLibrary.Data.S ql.SqlDatabase,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" />

</databaseTypes>

<instances>

<instance name="s11\eleven.prod" type="Sql Server"
connectionString="s11\eleven.prod" />

<instance name="s09\Magic.prod" type="Sql Server"
connectionString="s09\Magic.prod" />

</instances>

<connectionStrings>

<connectionString name="s11\eleven.prod">

<parameters>

<parameter name="database" value="jt1" isSensitive="false" />

<parameter name="Integrated Security" value="True" isSensitive="false" />

<parameter name="Max Pool Size" value="50" isSensitive="false" />

<parameter name="Min Pool Size" value="0" isSensitive="false" />

<parameter name="Connection Lifetime" value="30" isSensitive="false" />

<parameter name="Pooling" value="True" isSensitive="false" />

<parameter name="server" value="admsitsdbs11\eleven" isSensitive="false"
/>

</parameters>

</connectionString>

<connectionString name="s09\Magic.prod">

<parameters>

<parameter name="Connection Lifetime" value="30" isSensitive="false" />

<parameter name="database" value="s1" isSensitive="false" />

<parameter name="Integrated Security" value="True" isSensitive="false" />

<parameter name="Max Pool Size" value="5" isSensitive="false" />

<parameter name="Min Pool Size" value="0" isSensitive="false" />

<parameter name="Pooling" value="True" isSensitive="false" />

<parameter name="server" value="admsitsdbs09\magic" isSensitive="false" />

</parameters>

</connectionString>

</connectionStrings>

</enterpriseLibrary.databaseSettings>

</xmlSerializerSection>

</dataConfiguration>
Ok, and here is the code I'm trying to get to work. I've included
commented out XPath strings I've tried, which didn't work.

Dim filename As String

Dim ds As DataSet

Dim dt As DataTable

Dim row As DataRow

Dim config As XmlDataDocument

Dim node As XmlNode

Dim nodeList As XmlNodeList

Dim element As XmlElement

Dim nodePath As String

Try

filename = Application.StartupPath + "\" + "dataconfiguration.config"

ds = New DataSet

'ds.ReadXmlSchema(filename)

ds.ReadXml(filename)

config = New XmlDataDocument(ds)

'config.Load(filename)

'nodePath =
"//dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath =
"/dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath =
"dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings/connectionStrings"

'nodePath = "/dataConfiguration/xmlSerializerSection/*/connectionStrings"

'nodePath = "/*/*/*/connectionStrings"

'nodePath =
"descendant::dataConfiguration/xmlSerializerSection/enterpriseLibrary.databaseSettings"

'nodePath =
"descendant::xmlSerializerSection/enterpriseLibrary.databaseSettings"

'nodePath = "//connectionString"

nodePath = "/dataConfiguration/xmlSerializerSection/*/connectionStrings"

nodeList = config.SelectNodes(nodePath)

'nodeList =
config.ChildNodes(0).ChildNodes(0).ChildNodes(0).S electNodes("//connectionStrings")

Catch ex As Exception

Throw ex

End Try

Any advice you can offer is appreciated! Thanks in advance!

JB

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sami | last post: by
1 post views Thread by comic_rage | last post: by
5 posts views Thread by alf | last post: by
1 post views Thread by M Irfan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.