Reputation:
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");
Upvotes: 0
Views: 1603
Reputation: 13582
in the case of unrecognized escape sequence you need to do this :
"...\\SQLEXPRESS;..."
or as Harvey mentioned :
@"...\SQLEXPRESS;..."
they are both the same.
Upvotes: 0
Reputation: 103467
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");
Upvotes: 1
Reputation: 11873
Try this.
SqlConnection con = new SqlConnection(@"data source=APOORVA\SQLEXPRESS;initial catalog=mallinventory;integrated security=true");
Upvotes: 4