A connection string tells the board-game API which SQL Server database to use and how to connect. The example names a server and database and includes login credentials. EF Core uses the configured value to connect ApplicationDbContext to the database. section 4.3.4 section 4.5
Set up the connection in this order:
- Create the database, then create a SQL Server login and a database user linked to it. The login authenticates to the instance; the user controls access to that database. section 4.2.4
- Store the development connection string outside source control. Visual Studio Secret Manager is one option; an environment variable or an ignored development settings file are alternatives. section 4.3.4
- Register ApplicationDbContext with the SQL Server provider and retrieve the value named DefaultConnection. Once connected, EF Core migrations can create the database structure from the data model. section 4.3.4 section 4.5
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection"))
);
This Program.cs registration passes DefaultConnection from configuration to the SQL Server provider. section 4.3.4
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=MyBGList;
User Id=MyBGList;Password=MyS3cretP4$$;
Integrated Security=False;MultipleActiveResultSets=True;
TrustServerCertificate=True"
}
}
This development example shows the ConnectionStrings configuration key and a SQL Server value containing server, database, user ID, and password. section 4.3.4
Production needs its own database login, user, and connection string. Give the production login a different password from the development login. section 12.3.6






