✅ [ASP NET Core] How do i connect mssql db to vs code project?
I've got some problems with connecting db when i switched to vs code. Now when I try to make "DefaultConenction": "my connection string" it complains about \ in string.


20 Replies
I think connection string syntax is wrong
i copied this from visual studio and also i checked previous projects they also had \ in syntax
Can you paste the full string?
Data Source=DESKTOP-7IMIBG3\SQLEXPRESS;Initial Catalog=GiveawayWebAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False
Remove the space from initial catalog
it doesnt work. Also it doesnt work if i remove all spaces
Don't think that's the issue
but it does if i remove \
\ this is the issue escape char
ye. But how do i connect db if \ is part of connection string?
Replace \ with \
\
Double \\
Or you could use string literal
@" conn string = xyz\db;..."
Keep the connection string in a string literal
I did double \ and it worked
Great
Thank you
@женя. to explain what happened here. Characters that have a special meaning in strings, such as
\
which we use for example for new line character \n
and other similar characters need to get "escaped" so that compiler taked the backslash as a litteral character rather than trying to apply a special meaning to it
as explained by Shinigami, \
is the escape character, so double \\
works cuz first one escapes second one. If you put @
in front that escapes the whole string, thats what peole usually do so that you dont need to put backslashes to escape everywhereoh good to know
tyty

appriciate it ty
np
you might wanna
/close
the thread @женя. or is there anything left you wanna ask?oh right. I was thinking how does it work
thanks again