Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my windows application, i am getting the server name from the user and stores it in a string(say a).while using this string in connection string extra '\' character is coming when i am executing in debug mode
whats the reason?
here i used the server name as ADMIN\SQLEXPRESS
while executing, the server name is shows the value as ADMIN\\SQLEXPRESS
Please help me
Posted

Because, inside a string literal, the backslash must be escaped, that is you write

C#
string path = "ADMIN\\SQLEXPRESS";


to assign ADMIN\SQLEXPRESS to variable path. See "Escape Sequences" at MSDN[^]
 
Share this answer
 
v3
Comments
phil.o 17-Dec-15 2:49am    
Is it me or you did not escape the backslash in your example? :)
CPallini 17-Dec-15 3:24am    
Naaaaaaaaaaah, it is properly escaped...
Now.
:-)
phil.o 17-Dec-15 3:33am    
:)
You said: "when i am executing in debug mode"
That sounds like the issue is when you are looking at the value in the debugger.
If that is the case, then there is no actual problem, it is just that the debugger adds the extra backslash when it is displaying the string value.

So if you have a string that actually contains: ADMIN\SQLEXPRESS
The debugger will display this as: ADMIN\\SQLEXPRESS
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900