A simple tool to export data from SQL Server databases in various formats. Perfect for scheduled reports, data transfers, or one-off exports.
- Download the latest release from the releases page
- Extract the ZIP file to a folder of your choice (e.g., C:\Tools\MinimalSqlExport)
- Run
MinimalSqlExport.exe
- this creates default settings files in aprofiles
folder
After installation, the easiest way to get started is:
- Open Command Prompt or PowerShell
- Navigate to your installation folder:
cd C:\Tools\MinimalSqlExport
- Run:
MinimalSqlExport
- Follow the on-screen prompts to select options
Profiles make it easy to save your export settings:
- Find the
profiles
folder that was created during first run - Copy
default.json
and rename it (e.g.,customers.json
) - Edit the file with Notepad or any text editor:
- Change
Name
to match your file name (without .json) - Update
ConnectionString
to your database - Change
Query
to your SQL statement - Set
Format
to CSV, JSON, XML, TAB, YAML, or AUTO - Update
OutputDirectory
to where you want files saved
- Change
Example profile (customers.json):
{
"Name": "customers",
"ConnectionString": "Server=MyServer;Database=Sales;Integrated Security=True;Encrypt=False;TrustServerCertificate=True;",
"Query": "SELECT TOP 100 * FROM Customers WHERE Region = @Region",
"Format": "CSV",
"OutputDirectory": "C:\\Reports\\Daily",
"CommandTimeout": 30,
"Parameters": [
{
"Name": "@Region",
"Value": "East",
"Type": "NVarChar"
}
]
}
The Parameters
section lets you safely include variables in your SQL query, which helps prevent SQL injection attacks and makes your profiles more flexible.
Run a saved profile:
MinimalSqlExport -p customers
See all available profiles:
MinimalSqlExport -l
Run a profile but change the query:
MinimalSqlExport -p customers -q "SELECT * FROM Customers WHERE JoinDate > '2023-01-01'"
Change output format on the fly:
MinimalSqlExport -p customers -f JSON
Specify custom output file:
MinimalSqlExport -p customers -o "C:\Reports\customers-march.csv"
Enable email notifications for errors:
MinimalSqlExport -p customers -n
After completing an export, you can now automatically run a stored procedure to perform additional tasks such as:
- Recording the export in an audit table
- Moving or processing the output file
- Triggering additional business processes
- Sending notifications
Example profile with post-processing:
{
"Name": "customers-with-postprocess",
"ConnectionString": "Server=MyServer;Database=Sales;Integrated Security=True;",
"Query": "SELECT * FROM Customers",
"Format": "CSV",
"OutputDirectory": "C:\\Reports\\Daily",
"PostProcess": {
"Name": "sp_LogExportCompletion",
"Schema": "dbo",
"RequireSuccess": true,
"CaptureReturnValue": true,
"CommandTimeout": 30,
"Parameters": [
{
"Name": "ExportFileName",
"Type": "varchar",
"Size": 255,
"Value": "${ExportFileName}"
},
{
"Name": "ExportPath",
"Type": "varchar",
"Size": 500,
"Value": "${ExportFilePath}"
},
{
"Name": "RowCount",
"Type": "int",
"Value": "${RowCount}"
},
{
"Name": "ExportTimestamp",
"Type": "datetime",
"Value": "${Timestamp}"
}
]
}
}
You can use the following variables in your stored procedure parameters:
${ExportFilePath}
- Full path of the exported file${ExportFileName}
- Only the filename portion${RowCount}
- Number of rows exported${Timestamp}
- Current date/time (format: yyyy-MM-dd HH:mm:ss)
Configure email notifications through a dedicated config file (mailconfig.json
):
{
"SmtpServer": "smtp.example.com",
"SmtpPort": 587,
"UseSsl": true,
"Username": "notifications@example.com",
"Password": "your_secure_password",
"From": "sql-exports@example.com",
"To": "admin@example.com",
"Subject": "[MinimalSqlExport] SQL Export Notification",
"NotifyOnlyErrors": true
}
Enable notifications for a specific profile by setting:
"EnableMailNotification": true
MinimalSqlExport now uses Dapper for database interactions, which provides:
- Better performance and query efficiency
- Improved parameter handling
- Robust type conversions
- More reliable connection management
Control application logging through the logsettings.json
file:
{
"LogLevel": "Information"
}
Available log levels: Debug, Information, Warning, Error
- Open Task Scheduler (search in Start menu)
- Click "Create Basic Task"
- Name it (e.g., "Daily Customer Export")
- Set when to run it (daily, weekly, etc.)
- Choose "Start a program"
- Browse to your MinimalSqlExport.exe location
- Add arguments:
-p customers -f CSV -n
- Click Finish
Create a batch file (daily_exports.bat):
@echo off
cd /d "C:\Tools\MinimalSqlExport"
echo Exporting customers...
MinimalSqlExport -p customers -f CSV -n
echo Exporting orders...
MinimalSqlExport -p orders -f JSON -n
echo Done!
Then schedule this batch file instead.
- CSV: Standard comma-separated values
- JSON: JavaScript Object Notation
- XML: Extensible Markup Language
- TAB: Tab-separated values
- YAML: YAML Ain't Markup Language
- AUTO: Auto-detect from SQL Server's output format
You can customize how each format behaves in your profile:
"CSV": {
"Header": true,
"Delimiter": ",",
"Separator": ",",
"Decimal": "."
}
"XML": {
"AppendHeader": true,
"RootNode": "Customers",
"RowNode": "Customer"
}
"JSON": {
"WriteIndented": true
}
"YAML": {
"IncludeHeader": true,
"IndentationLevel": 2,
"EmitDefaults": false
}
Run in secure mode to validate queries before execution (helps prevent potentially dangerous SQL):
MinimalSqlExport -p profile -s
Get email when exports fail by enabling notifications:
MinimalSqlExport -p profile -n
You can also use PowerShell's Send-MailMessage
in a batch file for more control over notifications:
powershell -Command "Send-MailMessage -From 'alerts@mycompany.com' -To 'user@mycompany.com' -Subject 'SQL Export Completed' -Body 'The export has completed.' -SmtpServer 'smtp.mycompany.com'"