I have created a web application. I am trying to connect to MS Sql database through entity framework.
I have an issue in the below connection string in appsettings.json file.
In the connection string password contains semicolon as below.
DefaultConnection": "Server=server name; Database=my db; User Id=myuser; Password=HjkT;tk-k@=?55\; MultipleActiveResultSets=true;
while i am trying to access the entity framework getting this error
An unhandled exception occurred while processing the request.
ArgumentException: Keyword not supported: 'tk-k@'
I tried putting this password in double quotes/single quote/" . But still facing this error.
That's not appsettings.json
issue, it's connection string issue.
The basic format of a connection string includes a series of keyword/value pairs separated by semicolons. The equal sign (=) connects each keyword and its value. To include values that contain a semicolon, single-quote character, or double-quote character, the value must be enclosed in double quotation marks
from here
So your connection string shoud look like:
Server=server name; Database=my db; User Id=myuser; Password="HjkT;tk-k@=?55\"; MultipleActiveResultSets=true;
And as soon as quote and backslash are special symbols for json - you should escape them with backslash. Here is your file:
{
"DefaultConnection": "Server=server name; Database=my db; User Id=myuser; Password=\"HjkT;tk-k@=?55\\\"; MultipleActiveResultSets=true;"
}