Objective: Configure an ASP.NET Core Razor Pages application to access an existing SQL Server 2025 database through Entity Framework Core.
The modern equivalent of the legacy Data Environment is named configuration plus a database context registered with dependency injection. You do not add a Visual InterDev Data Environment, edit Global.asa, or attach the old virtualbook.mdb Access file.
Use BigBook as the sample project and database name and BigBookConn as the configuration key. This is the VirtualBookShelf course application under the name shown in the illustration. The preceding lesson uses VirtualBookShelfConnection; names are configurable, but the configuration key and code must agree throughout your project.
BigBook. Retain the template's middleware and security configuration.Microsoft.EntityFrameworkCore.SqlServer through Manage NuGet Packages using the matching EF Core major version. This provider uses Microsoft.Data.SqlClient.BigBook database on SQL Server 2025, its actual host and port, and permission for your Windows account to connect. No sample tables or Access download are needed for this connection-only exercise.ConnectionStrings entry to appsettings.json, merging it with the existing JSON. Replace the example host and port with your assigned SQL Server endpoint. Do not paste credentials into your submission.{
"ConnectionStrings": {
"BigBookConn": "Server=tcp:sql2025-host,1433;Database=BigBook;Integrated Security=True;Encrypt=True;TrustServerCertificate=False;"
}
}
Integrated Security=True uses the process's Windows identity. When launched locally from Visual Studio this is normally your Windows account; a hosted application may use a different identity. This sample intentionally contains no password. Use development User Secrets or an approved production secret store if your assigned authentication method requires secrets.
Data/BigBookContext.cs with a BigBookContext : DbContext class. Its public constructor must accept DbContextOptions<BigBookContext> and pass those options to the base constructor. No entity sets are needed for this connection check.Program.cs, register the context before builder.Build(). Use AddDbContext<BigBookContext>, UseSqlServer, and GetConnectionString("BigBookConn"). Keep the template's Razor Pages registration and middleware.builder.Build() and before app.Run(). Run in the Development environment and inspect the application log in Visual Studio's Output window or the console.// Temporary connection check, after builder.Build() and before app.Run().
if (app.Environment.IsDevelopment())
{
await using var scope = app.Services.CreateAsyncScope();
var db = scope.ServiceProvider.GetRequiredService<BigBookContext>();
bool connected = await db.Database.CanConnectAsync();
app.Logger.LogInformation("BigBook connection check: {Connected}", connected);
}
A True result establishes connectivity, not table availability, query permissions, or schema correctness. A False result requires investigation of the host, network, database name, Windows login, or certificate trust. Do not disable certificate validation to hide a connection problem. Remove the temporary check after recording your result.
Submit your redacted connection configuration, context constructor, registration code, and observed connection-check result. If you cannot run the application, say so and explain the expected check; do not claim an unobserved success. Do not include passwords, tokens, or private infrastructure details.
Submitting displays your response and a model solution. This page does not run your C# code, connect to your database, or automatically award points. Compare your work with this rubric.
BigBookContext accepts typed options and is registered with AddDbContext and UseSqlServer.