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
- Log in to Plesk
- Go to Websites & Domains
- Click Databases
- Click Add Database
- Select Microsoft SQL Server as the database type
- Enter a database name
- Create a database user with a strong password
- 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
- Go to .NET Core settings in Plesk
- 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
localhostor.as server name - Verify SQL Server is running
"Certificate chain" or SSL Errors
- Add
TrustServerCertificate=True;to connection string