Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"       }     }   } 
like image 737
nobody Avatar asked Jan 12 '17 23:01

nobody


People also ask

How do I pass username and password in SQL connection string?

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.

How do I create a connection string in .NET core?

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 .

How can create connection string 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.


2 Answers

user<space>id 

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

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

like image 70
Jeremy Cook Avatar answered Sep 23 '22 11:09

Jeremy Cook


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;"   } 
like image 34
Majid joghataey Avatar answered Sep 22 '22 11:09

Majid joghataey