Connecting .NET 11 Apps to MSSQL Databases Print

  • net11, dotnet 11, sql, mssql, ef core 11, connection string
  • 0

Overview

This guide covers connecting your .NET 11 application to Microsoft SQL Server (MSSQL) databases on our Windows hosting platform, including the Entity Framework Core 11 setting you need for SQL Server 2025 databases.

Creating a Database in Plesk

  1. Log in to Plesk
  2. Go to Websites & Domains
  3. Click Databases
  4. Click Add Database
  5. Select Microsoft SQL Server and choose the SQL Server 2025 or SQL Server 2022 server
  6. Enter a database name
  7. Create a database user with a strong password
  8. Click OK

Server Hostnames

Your application always connects over a public hostname with SQL Server Authentication and the database user you created in Plesk:

Server Hostname Port
SQL Server 2025 sql2025-001.adaptivewebhosting.com 1433 (default)
SQL Server 2022 sql2022-001.adaptivewebhosting.com 1433 (default)
SQL Server 2022 sql2022-002.adaptivewebhosting.com 1443

Plesk shows the server by its internal name (for example .\MSSQLSERVER2025). That name only works on the server itself; from your application always use the public hostname. If you are not sure which SQL Server 2022 hostname your database is on, open a support ticket and we will tell you.

Connection String Format

SQL Server 2025

Server=sql2025-001.adaptivewebhosting.com;Database=YOUR_DATABASE;User Id=YOUR_DB_USER;Password=YOUR_PASSWORD;Encrypt=True;TrustServerCertificate=True;MultipleActiveResultSets=true;

SQL Server 2022 on port 1443

Put a non-default port after the hostname with a comma:

Server=sql2022-002.adaptivewebhosting.com,1443;Database=YOUR_DATABASE;User Id=YOUR_DB_USER;Password=YOUR_PASSWORD;Encrypt=True;TrustServerCertificate=True;MultipleActiveResultSets=true;

Configuring Connection Strings

Option 1: appsettings.Production.json (Recommended)

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=sql2025-001.adaptivewebhosting.com;Database=mydb;User Id=myuser;Password=mypassword;Encrypt=True;TrustServerCertificate=True;MultipleActiveResultSets=true;"
  }
}

Option 2: Environment Variable in web.config

You can also set the connection string as an environment variable inside the <aspNetCore> element of your web.config:

<aspNetCore processPath=".\MyApp.exe" hostingModel="inprocess">
  <environmentVariables>
    <environmentVariable name="ConnectionStrings__DefaultConnection" value="Server=sql2025-001.adaptivewebhosting.com;Database=mydb;User Id=myuser;Password=mypassword;Encrypt=True;TrustServerCertificate=True;" />
  </environmentVariables>
</aspNetCore>

Entity Framework Core 11 Setup

Install the Package

dotnet add package Microsoft.EntityFrameworkCore.SqlServer

EF Core 11 requires .NET 11, so use it with a project that targets net11.0.

Configure in Program.cs (SQL Server 2022)

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

Configure in Program.cs (SQL Server 2025)

EF Core 11 assumes compatibility level 160 (SQL Server 2022) unless you tell it otherwise. To use SQL Server 2025 features such as JSON_CONTAINS on a SQL Server 2025 database at compatibility level 170, set it explicitly (check your database's level with the query below):

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(
        builder.Configuration.GetConnectionString("DefaultConnection"),
        sql => sql.UseCompatibilityLevel(170)));

Databases Moved From an Older Server

A database restored from an older SQL Server keeps its previous compatibility level. You can check it with:

SELECT compatibility_level FROM sys.databases WHERE name = DB_NAME();

If it is lower than 160, set UseCompatibilityLevel() to that number, or open a support ticket if you would like the level raised.

New in Entity Framework Core 11

  • JSON: EF.Functions.JsonPathExists() and EF.Functions.JsonContains()
  • Full-text search: HasFullTextIndex(), FreeTextTable and ContainsTable
  • Vector search: VectorSearch() and vector indexes (Microsoft notes these are still experimental in SQL Server). Vector columns are no longer loaded by default when you query whole entities.
  • Migrations tooling: dotnet ef database update --add and a .config/dotnet-ef.json settings file

Testing the Database Connection

// In a controller or page
try
{
    var ok = await _context.Database.CanConnectAsync();
    // ok == true means the connection works
}
catch (Exception ex)
{
    // Log the exception
}

Common Connection Issues

"Login failed for user" (error 18456)

  • Check the username and password
  • A login exists only on the server where it was created. A user made on SQL Server 2025 cannot log in to SQL Server 2022, and the other way round. Check the hostname.
  • Repeated failed logins can block your IP automatically. Fix the connection string before retrying many times.

Error 25 or 26, "A network-related or instance-specific error"

  • The connection string uses localhost, (local), . or an instance name such as .\MSSQLSERVER2025. Replace it with the public hostname from the table above.

"Cannot open database"

  • Check the database name for typos
  • Check that the database exists in Plesk and your user has access to it

"Certificate chain" or SSL Errors

  • Add Encrypt=True;TrustServerCertificate=True; to the connection string

Official documentation: What's new in EF Core 11

Looking for a host for your .NET 11 app? Our .NET 11 hosting plans include SQL Server 2025 and 2022 databases on every plan. Compare plans.

Was this answer helpful?

« Back