如何将具有反斜杠的连接字符串传递给SqlConnection?

我试图使用C#调用存储过程。

我在以下方面遇到问题。

SqlConnection("Server=DB2\XPT;DataBase=SCFHP_EDI_P1;Integrated Security=SSPI"); 

我无法使用的部分是服务器DB2\XPT

要将服务器名称用作DB2\XPT我需要做什么?

 ("Server=DB2\\XPT;DataBase=SCFHP_EDI_P1;Integrated Security=SSPI"); 

要么

 (@"Server=DB2\XPT;DataBase=SCFHP_EDI_P1;Integrated Security=SSPI") 

如果要避免在字符串中转义字符,则需要在连接字符串中转义反斜杠\或使用@符号。

在MSDN上阅读更多相关信息。

使用@符号更正语法1:

 SqlConnection(@"Server=DB2\XPT;DataBase=SCFHP_EDI_P1;Integrated Security=SSPI"); 

使用转义修正了语法2:

 SqlConnection("Server=DB2\\XPT;DataBase=SCFHP_EDI_P1;Integrated Security=SSPI");