'Setting connection string with username and password in ASP.Core MVC

I am working on my first ASP.NET Core MVC application.What is the right way to specify the connection string in a ASP.NET Core MVC application with a sql server backend requiring sql authentication?

ArgumentException: Keyword not supported: 'userid'.\

In the code below is my appsettings.json file.When I run the application it throws an error

{
  "ApplicationInsights": {
    "InstrumentationKey": ""
  },
  "ConnectionStrings": {
      "DefaultConnection": "Server=myserver;Database=mydatabase;userid=id;password=mypwd"
  },
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    }
  }


Solution 1:[1]

user<space>id

Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

https://www.connectionstrings.com/sql-server/

Solution 2:[2]

That's because the correct keyword is User Id, as shown in the following example:

"ConnectionStrings": {
    "DefaultConnection": "Server=myServerAddress;Database=myDataBase;User Id=myUsername;password=myPassword;Trusted_Connection=False;MultipleActiveResultSets=true;"
  }

Solution 3:[3]

Can you try User ID instead of userid?

Note the main difference is in the space between user and id, the case doesn't matter

Solution 4:[4]

Try this:

"ConnectionStrings": {
    "MvcMovieContext": "Server=localhost\\NOMINSTANCE;Database=NomBD;Trusted_Connection=True;MultipleActiveResultSets=true;User ID=sa;Password=password1;Integrated Security=False"
}

Solution 5:[5]

By setting Integrated security = false in your connection string in web.config file then this error will be solved

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Cook
Solution 2 Rik Sportel
Solution 3 Mickaƫl Derriey
Solution 4 Miguel Linares
Solution 5 alexander.polomodov