liveBook · Manning

Connection string

As explained in Pro ASP.NET Core 7, Tenth Edition

A connection string is a configuration value that specifies how software connects to a data source such as a database.

A connection string specifies how an application connects to a data source. In ASP.NET Core, store it as a named value under the `ConnectionStrings` object in `appsettings.json`, then retrieve it through configuration when setting up a database service. section 7.2.2 section 7.2.4

Listing 7.15 Adding a configuration setting in the appsettings.json file in the SportsStore folder
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "SportsStoreConnection": "Server=(localdb)\\MSSQLLocalDB;Database=
SportsStore;MultipleActiveResultSets=true"
  }
}

This LocalDB example stores a named SQL Server connection string in JSON. Keep the actual value on one unbroken line; line breaks in printed examples are for layout. section 7.2.2

Configure Entity Framework Core with the matching configuration key and database provider, such as `UseSqlServer` with `ConnectionStrings:SportsStoreConnection`. Connection-string formats vary by database server. The `MultipleActiveResultSets` option is used in examples where queries require multiple result sets. section 7.2.4 section 17.5.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines JSON placement, single-line formatting, LocalDB values, and EF Core lookup, while deferring broader configuration-file behavior.
Examples
Uses LocalDB databases named SportsStore, Products, People, CalcDb, and Identity.
What you can do after
Configure a database connection by storing a named value in appsettings.json and passing its configuration key to AddDbContext.
How it connects
Connects ASP.NET Core configuration with Entity Framework Core, SQL Server, and ASP.NET Core Identity.

Also explained in

Compare how 7 books explain connection string →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.