[英]Handle backslash in the connection string
I have a following connection string in app.config 我在app.config中有以下连接字符串
<add name="myDBConnectionString"
connectionString="Data Source=ASDFG\SQLEXPRESS;
Initial Catalog=ZAQ;
Integrated Security=True;"/>
in my C# code then, when I get this string DB is always evaluated as "ASDFG\\\\SQLEXPRESS"
然后在我的C#代码中,当我得到此字符串时,DB始终被评估为
"ASDFG\\\\SQLEXPRESS"
I couldn't put @ since app.config doesn't like it. 我不能放@,因为app.config不喜欢它。 Also, if I say
另外,如果我说
ASDFG\\SQLEXPRESS
it gets evaluated as 它被评估为
ASDFG\\\\SQLEXPRESS
and not open the connection. 而不打开连接。
Thank You, 谢谢,
调试器可能会将其显示为ASDFG\\\\SQLEXPRESS
,但只是出于显示目的转义了反斜杠。
use this in codebehind 在代码隐藏中使用它
string conString =
System.Configuration.ConfigurationManager
.ConnectionStrings["myDBConnectionString"].ToString();
always evaluated as "ASDFG\\SQLEXPRESS"
始终评估为“ ASDFG \\ SQLEXPRESS”
Which is quite correct. 这是正确的。 Any actual problems opening the Db?
打开Db有任何实际问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.