简体   繁体   中英

Unrecognisable escape sequence error

I just attached my database from some other computer to my computer.everything worked fine except of this data source.It is giving an error "Unrecognizable escape sequence".

I think the error is because of the back slash but I don't know how can I resolve it because my computer's server name is this only.Please help.

SqlConnection con = new SqlConnection("data source=APOORVA\SQLEXPRESS;initial catalog=mall inventory;integrated security=true");

尝试这个。

SqlConnection con = new SqlConnection(@"data source=APOORVA\SQLEXPRESS;initial catalog=mallinventory;integrated security=true");

The compiler was seeing \\S , and trying to interpret it as an escape-sequence (because it starts with a \\ ).

Either escape the backslash by doubling it:

SqlConnection con = new SqlConnection("data source=APOORVA\\SQLEXPRESS;initial catalog=mallinventory;integrated security=true");

Or use a verbatim string:

SqlConnection con = new SqlConnection(@"data source=APOORVA\SQLEXPRESS;initial catalog=mallinventory;integrated security=true");

in the case of unrecognized escape sequence you need to do this :
"...\\\\SQLEXPRESS;..."
or as Harvey mentioned :
@"...\\SQLEXPRESS;..."
they are both the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM