472,991 Members | 2,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Shared app.config

This situation requres many exes to be sitting on a network share. I would
like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist
in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function
Nov 20 '05 #1
5 6447
Assign them the same appDomain. I "believe" thats what is used to read the
app.config file... I could be wrong on that. But tests that I've done show
it.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I would like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function

Nov 20 '05 #2
Thanks CJ, so then I would be creating a new appdomain in my sub main? In
what way though do I instruct each exe to share this appdomain? Are the
parameters for itself somehow loaded from some additional universal file.
This is new territory for me.

Could you share and representative code please?

Eric
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Assign them the same appDomain. I "believe" thats what is used to read the app.config file... I could be wrong on that. But tests that I've done show it.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I

would
like all of these to use the same app.config file, which will be stored in the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not

exist
in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type) at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder? Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function


Nov 20 '05 #3
Your sub main creates an appdomain nonetheless on a current thread with the
same name as the executable.

So it looks like you can create a new Domain... and run
AppDomain.ExecuteAssembly() and get the desired results. I have never
actually done this, I'm just looking at things and think it can do it..

But hey, not a lot of code to test out..

Lookup AppDomain.ExecuteAssembly in your help file it gives an example.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks CJ, so then I would be creating a new appdomain in my sub main? In
what way though do I instruct each exe to share this appdomain? Are the
parameters for itself somehow loaded from some additional universal file.
This is new territory for me.

Could you share and representative code please?

Eric
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Assign them the same appDomain. I "believe" thats what is used to read the
app.config file... I could be wrong on that. But tests that I've done

show
it.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I

would
like all of these to use the same app.config file, which will be
stored in the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not

exist
in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type) at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder? Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function



Nov 20 '05 #4
The application configuration file must reside in the application directory
and must be named the same as the exe file, with a .config extension. For
example, if your application exe is "test.exe" the config file will be
"test.exe.config". The simplest way to solve your problem is to dynamically
copy the app.config master copy to the application directory for each
application, renaming it appropriately when the application starts. For
example, this code will work. Note that it only works as written in
*release* mode, not in debug mode. However, you can probably add an ifdef
and change the pathname for the copied file to make it work in either--I
didn't test that.

Also note that, as written, there's a hard-coded path to the master
app.config file in the code, which is generally a bad idea. You'd be better
off retreiving the master pathname from the Registry, from some text file,
passing it in as a startup parameter, or getting it from a database

Put this code in your startup form load or in the module containing Sub
Main, changing the master-location path and "someKey" appropriately.
Imports System.IO
Imports System.Reflection
' at startup in *RELEASE* mode
' get the location of this executable
Dim appLocation As String = [Assembly].GetExecutingAssembly.Location
File.Copy("master-location\app.config", appLocation & ".config", True)
' read the config file (proof that it works)
'
Debug.WriteLine(System.Configuration.Configuration Settings.AppSettings.Get("
someKey"))

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I would like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function

Nov 20 '05 #5
Eric,

You can put the settings in the machine.config file.
Its located in the CONFIG directory of the runtime install path
(System.Web.Hosting.SimpleWorkerRequest.MachineCon figPath Property will
return the path)
machine.config already contains an <appSettings> although it is commented
out
AppSettingsReader first checks this file before checking the applications
configuration file

Stephen

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I would like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function

Nov 20 '05 #6

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

Similar topics

0
by: Phil | last post by:
I realize this is the php group, but I have a question that recurses back to my php install. My objective is a pure 64 bit shared object installation of php 5.0 on UltraSparc Solaris 9 compiled...
0
by: John Dalberg | last post by:
I am trying to lock down file access of some sites in a shared hosting environment so that different users can only access their own site's directory with their asp.net code. However there's a...
9
by: Invalidlastname | last post by:
Hi, We developed some assemblies which use EnterpriseServices queued components. In order to use EnterpriseServices, these assemblies need to be installed into GAC. I used the pre-build and...
3
by: Sam-I-Am | last post by:
Hi all I have a common shared assembly in intalled in the GAC: myco.myprod.common.dll I have set a reference to this assembly in a asp.net web application. I have config sections in my...
27
by: Javier Martinez | last post by:
Hi I have asp application in a machine with a virtual directory referring a shared directory in another machine When I try to load any aspx page of my portal I get the following error: ...
33
by: Joe Fallon | last post by:
1. I have a Base class that has a certain amount of functionality. 2. Then I have a CodeSmith generated class that inherits from the Base class and adds functionality. 3. Since I want to be able...
4
by: a | last post by:
Hello Gang, I am in a bit of confusion regarding a half completed application I am writing. It is an MDI app, so I have a main form (frmMain) that is always open. I am looking for a 'Best...
1
by: QT | last post by:
Hi. Is it possible to use configuration files with a shared add-in component? I have added one to my solution for the add-in, but I can't pick up the values from my config file. If my...
4
by: Rubbrecht Philippe | last post by:
Hi there, I would like to develop an interface that when implemented in a class requires a number of shared properties or methods to be available. It seems a Shared Member can not be used as...
0
by: vikramp | last post by:
Hi, I am storing theme in web.config using <pages theme="mytheme"/>. I am then using the following code to read it from my webpage: Configuration config =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.