web.config backslash appears twice Visual Studio 2010

I have an asp.net web application that I made in Visual Studio 2008. Everything worked just fine until I switched to VS 2010. When that happened, I started seeing some weird behavior with my database connection string. The string (edited, but format is the same) is as follows:

<add name="DBname" connectionString="Data Source=SomeTextSomeMoreText;Initial Catalog=DB;Integrated Security=True" providerName="System.Data.SqlClient"/>

The problem is with the SomeTextSomeMoreText part.
When I run this in the debugger, the ‘’ is changed into ‘\’. This breaks everything.

My question, which probably has an extremely simple answer is this:
How can I get VS2010 to treat the connection string like a normal string without trying to insert the extra slash?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The extra slash is not there as far as interpretation of the string is concerned. It is merely an escape character ‘’ before the slash ‘’.

Want proof? Add the following to your code (with proper naming of course):

Debug.WriteLine(connectionStringValueHere);

Here is a small app:

        string test = "This\is\a\test";

        Console.WriteLine(test);
        Debug.WriteLine(test);

        Console.Read();

Note that the string, in both console and debug (output window) is Thisisatest. If you do the following in the immediate window when the code is at a breakpoint:

 ? test

You see the following output

? test
"This\is\a\test"

But you have the escapes present, which is normal for strings in .NET.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x