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.
json file, right click on the Project in Solution Explorer. Then click Add, then New Item and then choose App Settings File option (shown below) and click Add button. Once the File is created, it will have a DefaultConnection, below that a new Connection String entry is added.
In ASP.NET Core the configuration system is very flexible, and the connection string could be stored in appsettings. json , an environment variable, the user secret store, or another configuration source. See the Configuration section of the ASP.NET Core documentation for more details.
The appsettings. json file is generally used to store the application configuration settings such as database connection strings, any application scope global variables, and much other information.
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;"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With