By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

use single user.config for multiple .exe projects

P: n/a
Two of the projects in my solution that both need to use a common
user.config file. This is a data application - the executable that is
created with the first project is the primary executable that users will be
working with 99% of the time, the other is a seperate "maintenance"
executable. The connection string is stored via My.Settings (encrypted of
course). The problem is that obviously with 2 different .exe there are 2
seperate user.config files, but I need to read the connection string out of
a single file. Is this even possible? If not, are there any other
suggestions for how to acheive this same type of functionality through other
Feb 5 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Matt,

Firstly, in .NET 2.0, there are two kinds of application settings, i.e.
application-scoped settings and user-scoped settings. After the project is
compiled, the values of the application-scoped settings and the default
values of the user-scoped settings are stored in the application's config
file, named applicationname.exe.config in the same path of the exe file.

When the application is run, and the user changes the value of the
user-scoped settings and save them back to the disk, the new value of the
user-scoped settings are saved in another config file named user.config
located at the current user's application data path.

You have mentioned that you'd like to access the connection string stored
in one config file in two different applications. A connection string
setting should be a application-scoped setting and stored in
applicationname.exe.config file.

Yes, it's possible to do what you want, because actually config file is XML
formatted. We could regard the config file as a normal XML file.

The following is a sample.

Imports System.Xml

Private Function GetValueFromConfig(ByVal filepath As String, ByVal
connstrname As String) As String
Dim connstr As String = ""
Dim doc As New XmlDocument

Dim connode As XmlNode = doc.SelectSingleNode("//connectionStrings")
Dim connChildnodes As XmlNodeList = connode.ChildNodes
Dim connChildnode As XmlNode
Dim nameAttr, connAttr As XmlAttribute

For Each connChildnode In connChildnodes
nameAttr = connChildnode.Attributes("name")
If (nameAttr.InnerText = connstrname) Then
connAttr = connChildnode.Attributes("connectionString")
Exit For
End If
If Not (connAttr Is Nothing) Then
connstr = connAttr.InnerText
End If

Return connstr
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
dim connstr as string = Me.GetValueFromConfig("config1.config", "name
of the connection string setting")
End Sub

Hope this helps.
If you have any question, please feel free to let me know.
Linda Liu
Microsoft Online Community Support

Get notification to my posts through email? Please refer to

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 6 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.