Reputation: 11090
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"
}
}
}
Upvotes: 58
Views: 232330
Reputation: 22073
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/
Upvotes: 103
Reputation: 189
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"
);
}
}
Upvotes: 2
Reputation: 1792
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;"
Upvotes: 5
Reputation: 29
Try this:
"ConnectionStrings": {
"MvcMovieContext": "Server=localhost\\NOMINSTANCE;Database=NomBD;Trusted_Connection=True;MultipleActiveResultSets=true;User ID=sa;Password=password1;Integrated Security=False"
}
Upvotes: 2
Reputation: 1537
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;"
}
Upvotes: 50
Reputation: 35
By setting Integrated security = false
in your connection string in web.config
file then this error will be solved
Upvotes: -2
Reputation: 13704
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
Upvotes: 4