Read Configuration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cacho

    #1

    Read Configuration

    Hi All

    I'm totally new to vbasic net and need to get values from a config files
    in the way:

    <configuratio n>
    <appSettings>
    <add key="Desvio" value="65282561 6" />
    <add key="MargenStri ng" value="10" />
    </appSettings>
    </configuration>


    Could somebody give and example of how to do it ?


    Thanks in advance

    X
  • Mattias Sjögren

    #2
    Re: Read Configuration

    [color=blue]
    >Could somebody give and example of how to do it ?[/color]

    System.Configur ation.Configura tionSettings.Ap pSettings("Desv io")


    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Cacho

      #3
      Re: Read Configuration

      Mattias Sjögren wrote:[color=blue][color=green]
      >>Could somebody give and example of how to do it ?[/color]
      >
      >
      > System.Configur ation.Configura tionSettings.Ap pSettings("Desv io")
      >[/color]


      Thanks for your reply.

      I did in that way but it didn't worked and I'm going to be crazy !>..

      I did:

      Dim ConnectionStrin g As String
      Dim MargenString As String
      Dim Desvio As String

      Desvio = System.Configur ation.Configura tionSettings.Ap pSettings("Desv io")
      System.Console. WriteLine(Desvi o)

      MargenString =
      System.Configur ation.Configura tionSettings.Ap pSettings("Marg enString")
      System.Console. WriteLine(Marge nString)

      ConnectionStrin g =
      System.Configur ation.Configura tionSettings.Ap pSettings("Conn ectionString")
      System.Console. WriteLine(Conne ctionString)

      --------------

      and in config file I've:

      <configuratio n>
      <appSettings>
      <add key="Desvio" value="65282561 6" />
      <add key="MargenStri ng" value="10" />
      </appSettings>
      </configuration>



      But when I run my application I see:

      ---------
      C:\tmp1>.\prueb aSQL.exe


      Network Library=DBMSSOC N;Data Source=localhos t;Initial atalog=segex;Us er
      ID=sa;Password= sa
      ----------------


      Program showed me the string of a parameter I deleted from config file
      and didn't show me exsitent parameters !!!

      How is posible ? Am I doing something wrong ? Is there a kind of cache
      that keeps data ?

      Thanks in advance

      X



      Comment

      • Phil G.

        #4
        Re: Read Configuration

        This 'should' work! Personally I like to import the classes to reduce coding
        and make it more manageable BUT it makes no difference to the operation of
        the code.

        Imports System.Configur ation.Configura tionSettings

        Private Sub AppConfig

        Dim Desvio,MargenSt ring as String
        Desvio = AppSettings("De svio")
        MargenString = AppSettings("Ma rgenString")

        End Sub

        I wonder if you have edited the correct app.config file. You might want to
        check in the IDE AFTER you have built your project. Select to view all files
        and review the contents of the .exe.config file in your bin subdir.

        HTH, Phil


        "Cacho" <jleyba@manresa .net> wrote in message
        news:u8IZhwwuFH A.2072@TK2MSFTN GP14.phx.gbl...[color=blue]
        > Mattias Sjögren wrote:[color=green][color=darkred]
        >>>Could somebody give and example of how to do it ?[/color]
        >>
        >>
        >> System.Configur ation.Configura tionSettings.Ap pSettings("Desv io")
        >>[/color]
        >
        >
        > Thanks for your reply.
        >
        > I did in that way but it didn't worked and I'm going to be crazy !>..
        >
        > I did:
        >
        > Dim ConnectionStrin g As String
        > Dim MargenString As String
        > Dim Desvio As String
        >
        > Desvio = System.Configur ation.Configura tionSettings.Ap pSettings("Desv io")
        > System.Console. WriteLine(Desvi o)
        >
        > MargenString =
        > System.Configur ation.Configura tionSettings.Ap pSettings("Marg enString")
        > System.Console. WriteLine(Marge nString)
        >
        > ConnectionStrin g =
        > System.Configur ation.Configura tionSettings.Ap pSettings("Conn ectionString")
        > System.Console. WriteLine(Conne ctionString)
        >
        > --------------
        >
        > and in config file I've:
        >
        > <configuratio n>
        > <appSettings>
        > <add key="Desvio" value="65282561 6" />
        > <add key="MargenStri ng" value="10" />
        > </appSettings>
        > </configuration>
        >
        >
        >
        > But when I run my application I see:
        >
        > ---------
        > C:\tmp1>.\prueb aSQL.exe
        >
        >
        > Network Library=DBMSSOC N;Data Source=localhos t;Initial atalog=segex;Us er
        > ID=sa;Password= sa
        > ----------------
        >
        >
        > Program showed me the string of a parameter I deleted from config file and
        > didn't show me exsitent parameters !!!
        >
        > How is posible ? Am I doing something wrong ? Is there a kind of cache
        > that keeps data ?
        >
        > Thanks in advance
        >
        > X
        >
        >
        >[/color]


        Comment

        Working...