SqlConnection构造函数中无法识别的转义序列
当我连接它时会出错
无法识别的转义序列。
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");
逃脱\字符如:
SqlConnection con = new SqlConnection("Server=NEPOLEON\\ADMN;Database=MASTER;Trusted_Connection=True");
要么
SqlConnection con = new SqlConnection(@"Server=NEPOLEON\ADMN;Database=MASTER;Trusted_Connection=True");
尝试将其更改为:
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中,您可以通过在字符串前面放置@
或使用特殊值来表示要转义的字符来转义特殊字符。 在这种情况下,您可以使用\\
来表示\