App.config \ becomes \\

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DragonLord
    New Member
    • Mar 2007
    • 122

    App.config \ becomes \\

    I am trying to read my database name from the app.config file in C#

    in the app.config it is stored as
    Code:
    <add key="DataBaseServer" value="Q-x\x"/>
    but when i say
    Code:
    _ServerName = ConfigurationManager.AppSettings.Get("DataBaseServer");
    it comes out as

    "Q-x\\x" which of course causes my connection string i am building to fail due to the double \

    how can i fix this so that it comes out with only one slash???

    Appreciate the help!!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Where are you seeing that double slash?
    I bet if you printed the value out to the console window (which is available to you in debug mode under the title of "Output") that there is only one slash

    I am assuming that "Q-x\x" is a madeup name, since I don't believe that is a valid servername? Hmm well maybe it is, but pretty sure the - is not allowed in server names, only _

    Comment

    • nateraaaa
      Recognized Expert Contributor
      • May 2007
      • 664

      #3
      You could also do a string.Replace on the string that is returned with the \\ and replace \\ with \.

      Nathan

      Comment

      Working...