本文介绍了在连接字符串中处理反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在app.config中有以下连接字符串

I have a following connection string in app.config

<add name="myDBConnectionString"
     connectionString="Data Source=ASDFG\SQLEXPRESS;
         Initial Catalog=ZAQ;
         Integrated Security=True;"/>

然后在我的C#代码中,当我得到此字符串时,DB始终被评估为 ASDFG\\SQLEXPRESS

in my C# code then, when I get this string DB is always evaluated as "ASDFG\\SQLEXPRESS"

我不能放@,因为app.config不喜欢它。另外,如果我说

I couldn't put @ since app.config doesn't like it. Also, if I say

ASDFG\\SQLEXPRESS 

它被评估为

ASDFG\\\\SQLEXPRESS 

,并且不打开连接。

谢谢

推荐答案

调试器可能会将其显示为 ASDFG\\SQLEXPRESS ,但这只是出于显示目的而转义了反斜杠。

The debugger may display it as ASDFG\\SQLEXPRESS, but it's just escaping that backslash for display purposes.

这篇关于在连接字符串中处理反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 07:00