c# - asp.net 中无法识别的转义字符

标签 c# asp.net database configurationmanager

我的 .cs 文件中有以下代码:

string connectionString= "SUMAN-PC\SQLEXPRESS;Initial Catalog=northwind;Integrated Security=True"; 

它会产生错误,因为“\”字符无法识别转义字符。如何解决这个问题?

注意:它在.cs文件里,不在web.config里

最佳答案

您没有转义反斜杠。这可以像这样完成

string connectionString= @"SUMAN-PC\SQLEXPRESS;Initial Catalog=northwind;Integrated Security=True";

-> 以@为前缀的字符串


string connectionString= "SUMAN-PC\\SQLEXPRESS;Initial Catalog=northwind;Integrated Security=True";

-> 用另一个反斜杠作为前缀

关于c# - asp.net 中无法识别的转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24302449/

相关文章:

c# - 如何在没有 WebBrowser 控件的情况下使用 "render"HTML

c# - Dapper 和字符串到自定义类型的隐式转换

c# - 自定义 .config 文件中无法识别的属性 'xmlns'

sql-server - 在 SQL SERVER 2008 的检查约束中创建自定义错误消息

c# - 如何从 .Net 程序运行 Import-PSSessions

c# - 数据表与 IEnumerable<T>

asp.net - 在运行时获取 IIS 绑定(bind)

asp.net - ASP 按钮(命令与提交)

java - Spring 的 JdbcTemplate 是否在查询超时后关闭连接?

mysql - 在 MySQL 中将数据从一列移动到另一列