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" } } }
Using a non-standard portServer=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword; The default SQL Server port is 1433 and there is no need to specify that in the connection string.
ASP.NET Core For instance, you can use the Secret Manager tool to store your database password and then, in scaffolding, use a connection string that simply consists of Name=<database-alias> . Or the following example shows the connection string stored in appsettings. json .
Adding the AppSettings.json file 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.
user<space>id
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;
https://www.connectionstrings.com/sql-server/
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;" }
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