52

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"
      }
    }
  }

7 Answers 7

96

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/

49

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;"
  }
4

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

2

Try this:

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

Please try this followingcode one: with latest Visual Studio 2022 it works

"ConnectionStrings": "Server=ServerAddress;Database=DatabaseName;User Id=User;password=Password;Trusted_Connection=SSPI;Encrypt=false;TrustServerCertificate=true;MultipleActiveResultSets=true;"
1

Please write bellow code in dbcontext file

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(
                    @"Server =.; Database = MyDb; User id=uid; Password=pwd; Trusted_Connection = True; MultipleActiveResultSets = true"
                );
            }
        }
-2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.