Search code examples
c#asp.net-coreasp.net-core-mvc

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'.\

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

  • User Id is the correct way, with space in the middle

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

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