Connecting .NET 10 Apps to MSSQL Databases Print

  • 0

Overview

This guide covers connecting your .NET 10 application to Microsoft SQL Server (MSSQL) databases on our Windows hosting platform.

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 as the database type
  6. Enter a database name
  7. Create a database user with a strong password
  8. Click OK

Connection String Format

Use this format for your connection string:

Server=localhost;Database=YOUR_DATABASE;User Id=YOUR_USER;Password=YOUR_PASSWORD;TrustServerCertificate=True;

For Windows Authentication (if available):

Server=localhost;Database=YOUR_DATABASE;Integrated Security=True;TrustServerCertificate=True;

Configuring Connection Strings

Option 1: appsettings.Production.json (Recommended)

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=mydb;User Id=myuser;Password=mypassword;TrustServerCertificate=True;"
  }
}

Option 2: Environment Variables in Plesk

  1. Go to .NET Core settings in Plesk
  2. Add environment variable:
ConnectionStrings__DefaultConnection=Server=localhost;Database=mydb;User Id=myuser;Password=mypassword;TrustServerCertificate=True;

Entity Framework Core 10 Setup

Install Required Package

dotnet add package Microsoft.EntityFrameworkCore.SqlServer

Configure in Program.cs

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

New in Entity Framework Core 10

  • LeftJoin/RightJoin: Direct LINQ support for LEFT/RIGHT joins
  • Vector Search: AI-ready vector search capabilities
  • Native JSON: Native JSON data types in Azure SQL and SQL Server
  • Named Query Filters: Multiple filters per entity with selective disabling

Testing Database Connection

Add this test code to verify your connection:

// In a controller or page
try
{
    await _context.Database.CanConnectAsync();
    // Connection successful
}
catch (Exception ex)
{
    // Log the exception
}

Common Connection Issues

"Login failed for user"

  • Verify username and password are correct
  • Check user has access to the database in Plesk

"Cannot open database"

  • Verify database name is spelled correctly
  • Ensure database exists in Plesk

"A network-related error"

  • Use localhost or . as server name
  • Verify SQL Server is running

"Certificate chain" or SSL Errors

  • Add TrustServerCertificate=True; to connection string

Was this answer helpful?

« Back