Results 1 to 3 of 3

Thread: [2005] Where is my problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Question [2005] Where is my problem

    Greetings,

    When I try to run this code i get most time a exception in the part
    Catch exc As Exception
    It is a IOException
    The Process can not access the file D:\views\pledlm_view\applications\ktr\source\KTR Client\KTR Client\bin\Release\KTR Client.exe.config because another process is using it.

    Background:
    1. The app = not MutliThreating
    2. I use the routine to add a new value in to the App.config

    For easier understanding i posted the whole class as zip to the thread


    VB Code:
    1. Private Function LoadConfigSource() As String
    2.  
    3.         Dim dllPath As String = System.Reflection.Assembly.GetExecutingAssembly.Location
    4.         Dim filename As String
    5.  
    6. #If DEBUG Then
    7.         '--> if debug app.config file is not in bin folder
    8.         Dim strTemp As String = Path.GetDirectoryName(dllPath)
    9.         strTemp = strTemp.Substring(1, strTemp.Length - 1)
    10.         strTemp = strTemp.Substring(1, strTemp.LastIndexOf("\bin\"))
    11.         filename = strTemp & "app.config"
    12. #Else
    13.         '--> get the name of the calling assembly (in the testcase TestConfigProvider) and built the path of the config file in release mode
    14.         filename = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\" & System.Reflection.Assembly.GetEntryAssembly.GetName.Name.ToString & ".exe.config"
    15. #End If
    16.         configSource = New XmlDocument
    17.  
    18.         Dim cstream As Stream
    19.  
    20.         Try
    21.             cstream = File.OpenRead(filename)
    22.             configSource.Load(cstream)
    23.  
    24.         Catch ex As FileNotFoundException
    25.             Throw ex
    26.         Catch exc As Exception
    27.             Throw exc
    28.         Finally
    29.             If Not cstream Is Nothing Then cstream.Close()
    30.         End Try
    31.  
    32.         Return filename
    33.  
    34.     End Function

    Thanks for any help
    Attached Files Attached Files

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Where is my problem

    You shouldn't be opening the config file durectly anyway. Access it via the System.Configuration namespace. Look at the ConfigurationManager.OpenExeConfiguration method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: [2005] Where is my problem

    @jmcilhinney:

    ok I am using now (which is match more easier could remove the whol.e class)the following line to get a value from the appsettings
    Code:
    cstMonthView.BColor1 = ConfigurationManager.AppSettings.Get("ABC")
    but and sorry jmcilhinney when i do the following line of code

    Code:
    ConfigurationManager.AppSettings.Set("ABC", "Red")
    the value is only temporary availible.

    After starting the app again the Value "Red" is not in the app.config
    So it seams to me the value are never writen to the key in the app.config

    For simplicity i replaced here the org code with dummy Values and keys.

    The original Lines would be for get
    Code:
    Color.FromName(ConfigurationManager.AppSettings.Get(My.Resources.KonfigKalenderBackColor1))
    and for set
    Code:
    cstMonthView.BColor1 = Color.FromName(ConfigurationManager.AppSettings.Get(My.Resources.KonfigKalenderBackColor1))
    Last edited by Bongo; Feb 26th, 2007 at 08:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width