Guide
SQL Server Express 2025: schedule and email a query
SQL Server Express has no SQL Agent. Schedule a query and email the result as CSV with Task Scheduler, sqlcmd and PowerShell, and what breaks later.
Guide
SQL Server Express has no SQL Agent. Schedule a query and email the result as CSV with Task Scheduler, sqlcmd and PowerShell, and what breaks later.
SQL Server Express runs a surprising amount of real business. A line of business application ships with it, the database grows for years under its size limit, and eventually someone asks for a daily list of something to land in their inbox. On Standard or Enterprise that is an Agent job calling Database Mail. On Express both pieces are missing: there is no SQL Server Agent service, and Database Mail is not a supported feature of the edition.
SQL Server 2025 did not change that. Express 2025 raises the database size limit from 10 GB to 50 GB and now includes everything that used to need Express with Advanced Services, which is why many teams are upgrading their Express servers this year. Microsoft's own 2025 edition table still lists SQL Server Agent and Database Mail as not available on Express, so the reports have to be scheduled the same way after the upgrade as before it.
The work does not change, only the scheduler and the mailer move outside the database.
PowerShell with the SqlServer module does the query and the CSV in two lines, and handles quoting correctly, which is more than Database Mail does:
Import-Module SqlServer
$file = "C:\exports\open_orders_$(Get-Date -Format yyyyMMdd).csv"
Invoke-Sqlcmd -ServerInstance ".\SQLEXPRESS" -Database "Sales" `
-Query "SELECT order_id, customer_name, total, created_at FROM dbo.orders WHERE status = 'open'" `
-TrustServerCertificate |
Export-Csv -Path $file -NoTypeInformation -Encoding UTF8
Without the module, sqlcmd -S .\SQLEXPRESS -d Sales -E -Q "..." -s "," -W -o file.csv writes a separated file, with the same quoting problems as Database Mail and a dashed line under the header that -h -1 removes along with the header itself.
This is the part with the most outdated advice online. Send-MailMessage still appears in most answers, but Microsoft marks it obsolete and it does not support modern authentication, so it fails against Microsoft 365 mailboxes that have basic SMTP authentication disabled. The options that keep working:
sendMail API with an app registration, via the Microsoft.Graph PowerShell moduleInvoke-RestMethodEach of them needs a secret stored somewhere on the server, and that secret is the piece most often found in a script in plain text a year later.
Windows Task Scheduler runs the script daily at a fixed time:
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -File C:\exports\open_orders.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 7am
Register-ScheduledTask -TaskName "Open orders export" -Action $action -Trigger $trigger -User "DOMAIN\svc-reports" -Password "..."
The account matters. If the task runs as the person who wrote it, it stops when their password changes or when they leave. A dedicated service account with read access to the database avoids that, and with Windows authentication there is no database password in the script at all.
None of it is visible from the database. The query lives in a .ps1 file on one server, the recipients are hardcoded, failures appear in the Task Scheduler history that nobody opens, and the next person to inherit the server finds out about the report when it stops. One script is fine. Five scripts on two servers are a small undocumented system.
Taavik's scheduled exports treat Express like any other SQL Server. An agent runs on a machine in the same network, often the same Windows server, and makes only outbound connections to the workspace. The query goes into a shared library where the rest of the team can read it, the schedule runs daily, weekly, monthly, on an interval or on cron with the Pro plan, and the result arrives as a properly quoted CSV or an Excel file through an email list or a Slack channel.
There is no SMTP relay and no mail secret to keep on the server, because delivery happens from the workspace. The trade-off is that recipients get a link to an encrypted file and open it with a passphrase, rather than an attachment. Every run is recorded, so "did it go out today" has an answer that does not require logging into the server.
The free plan covers one database connection and one daily schedule, which is exactly the size of the first Express report most teams need to replace.
Upgrading the Express instance itself? The SQL Server 2025 upgrade checklist covers what to capture before and compare after.