473,385 Members | 2,210 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,385 software developers and data experts.

use single user.config for multiple .exe projects

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
methods?
Feb 5 '07 #1
1 5113
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
doc.Load(filepath)

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
Next
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.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

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
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

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

Feb 6 '07 #2

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

Similar topics

1
by: RK | last post by:
Hi I am working on C# application, where in I may require just one app.config for the C#.NET solution with multiple windows application projects. I know one web.config can be used for multiple...
0
by: Mark | last post by:
We have multiple projects that we are going to place in the virtual directory on our web server. For example, we might have project1, project2, and project3, and each has there own set of .dll. ...
5
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to...
2
by: Samuel L Matzen | last post by:
Hi, I am trying to develop with multiple projects in a single solution. The many of these projects create .dlls that are used by other projects. When I reference a .dll I reference it in the...
2
by: mamatha k via .NET 247 | last post by:
(Type your message here) i have 5 projects in a single solution file of the VB.NET.Onlyone project is the startup project and another projects containsthe class files.I want the startup project uses...
3
by: kamere | last post by:
For your N-tier solutions. Have you architected your UI, Business, and DAL layers into one single project or have you separated them out into separate projects? What would be the benefits of...
6
by: Mr Flibble | last post by:
Hi all, I've decided to use log4net for my logging/tracing. In the example on the site it shows using main() to setup the root logger and then using the LogManager within your classes to...
2
by: Paul Cheetham | last post by:
Hi, We are developing a large modular application, and in order to simplify splitting of work between developers etc. we want to develop it using several different projects, and then combine the...
10
by: Scott Townsend | last post by:
So I'm trying to Write a Backend to something and in testing I decided to create a generic front end app that can simulate the passed in Data. So I have 2 projects in my solution, though I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.