Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Write connection string in asp.net core Web Api?

I want to create the database connection in my .net core Web API how to I write the connection string. In App setting file how to I write the connection string.

like image 522
Admin Avatar asked Dec 01 '16 14:12

Admin


People also ask

How to read a connection string in an ASP NET web application?

You need to use the connectionStrings tag to specify the connection string in the web.config file as in the following image. Write this XML markup in the web config file for declaration of the connection. You can add many tags for each database connection. Now I will describe how to read a web.config connection string in an ASP.NET web application.

How to write a connection string in a web config file?

Specify it in the web.config file. Create a common class file for the connection string. The benefit of writing a connection string in a web config file is there is no need to write code every time to connect to the database. It reduces the redundancy of code over a single application.

How do I add a connection string to a web application?

Open the application root Web.config file shown below. (Not the Web.config file in the Views folder.) Add the following connection string to the <connectionStrings> element in the Web.config file. The following example shows a portion of the Web.config file with the new connection string added: The two connection strings are very similar.

How do I create an API in ASP NET Core?

From the File menu, select New > Project. Select the ASP.NET Core Web API template and click Next. Name the project TodoApi and click Create. In the Create a new ASP.NET Core Web Application dialog, confirm that .NET Core and ASP.NET Core 5.0 are selected.


1 Answers

I got my answer

"Data": {
  "DefaultConnection": {
    "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet5-ConfigurationSample-ad90971f-6620-4bc1-ad28-650c59478cc1;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}

here is link http://aspnetmonsters.com/2016/01/json-config-in-aspnetcoremvc/

like image 89
Admin Avatar answered Oct 20 '22 00:10

Admin