【问题标题】:Unrecognized escape sequence in SqlConnection constructorSqlConnection 构造函数中无法识别的转义序列
【发布时间】:2012-09-25 15:22:05
【问题描述】:

每当我建立连接时,它都会出错

无法识别的转义序列。

NEPOLEON\ADMN HERE ON THIS SLASH. NEPOLEON\ADMN IS MY SQL SERVER NAME.

SqlConnection con = new SqlConnection("Server=NEPOLEON\ADMN;Database=MASTER;Trusted_Connection=True");

【问题讨论】:

  • 您在适当的时候提出问题以获得正确的答案并避免否定投票的最佳时间......现在由我编辑......

标签: c# sqlconnection


【解决方案1】:

转义 \ 字符,如:

SqlConnection con = new SqlConnection("Server=NEPOLEON\\ADMN;Database=MASTER;Trusted_Connection=True");

SqlConnection con = new SqlConnection(@"Server=NEPOLEON\ADMN;Database=MASTER;Trusted_Connection=True");

【讨论】:

    【解决方案2】:

    尝试将其更改为:

    SqlConnection con = new SqlConnection("Server=NEPOLEON\\ADMN;Database=MASTER;Trusted_Connection=True");
    

    或者这个

    SqlConnection con = new SqlConnection(@"Server=NEPOLEON\ADMN;Database=MASTER;Trusted_Connection=True");
    

    在 .NET 中,您可以通过在字符串前面放置 @ 或使用特殊值来表示要转义的字符来转义特殊字符。在这种情况下,您可以使用\\ 来表示\

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      相关资源
      最近更新 更多