SmartTableSync 0.5.2
See the version list below for details.
dotnet add package SmartTableSync --version 0.5.2
NuGet\Install-Package SmartTableSync -Version 0.5.2
<PackageReference Include="SmartTableSync" Version="0.5.2" />
<PackageVersion Include="SmartTableSync" Version="0.5.2" />
<PackageReference Include="SmartTableSync" />
paket add SmartTableSync --version 0.5.2
#r "nuget: SmartTableSync, 0.5.2"
#:package SmartTableSync@0.5.2
#addin nuget:?package=SmartTableSync&version=0.5.2
#tool nuget:?package=SmartTableSync&version=0.5.2
SmartTableSync
A self-configuring .NET engine that keeps tables synchronized from one SQL database to another (parent to child). Give it table names: it inspects each table's schema, picks how to detect changes and how to merge them, and keeps the child up to date on the schedule your host chooses.
Built for Azure SQL Database, where it runs in production, and works with Azure SQL Managed Instance and SQL Server (on-premises or in a VM) in any combination.
What it does
- Syncs the tables you list, one way: inserts, updates and deletes.
- Chooses per table how to find changed rows: SQL Server Change Tracking, a
rowversioncolumn, a timestamp column, or a full re-scan for small tables. - Copies a new table in full once, then only what changed, and resumes where it stopped.
- Needs no DDL rights at run time and signs in with managed identities or any SQL Server sign-in.
- Notices schema changes in the parent; in Auto mode it adds new columns to the child by itself.
Install
dotnet add package SmartTableSync
That's the only package you need: it includes every sign-in method, from SQL logins and Windows
authentication to managed identities and other Microsoft Entra methods
(Authentication=Active Directory ... in the connection string).
Use it
Register the engine and run it on your own schedule, here every 5 minutes in a background service:
using SmartTableSync.Abstractions;
using SmartTableSync.Hosting;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSmartTableSync();
builder.Services.AddHostedService<SyncWorker>();
builder.Build().Run();
public sealed class SyncWorker(ISyncOrchestrator orchestrator) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using var timer = new PeriodicTimer(TimeSpan.FromMinutes(5));
do
{
await orchestrator.RunAsync(stoppingToken);
}
while (await timer.WaitForNextTickAsync(stoppingToken));
}
}
appsettings.json:
{
"ParentDbConnectionString": "Server=tcp:myserver.database.windows.net,1433;Database=ParentDb;Authentication=Active Directory Managed Identity;User Id=<client id>;Encrypt=True",
"ChildDbConnectionString": "Server=tcp:myserver.database.windows.net,1433;Database=ChildDb;Authentication=Active Directory Managed Identity;User Id=<client id>;Encrypt=True",
"SmartTableSync": {
"TableList": "Product,Customer,sales.Order",
"Mode": "Manual"
}
}
The child database needs a table, a table type and a merge procedure for every synced table.
In Manual mode (the default) you create them from the scripts of the
SmartTableSync.Scaffold tool; in Auto
mode the engine creates them itself with a separate provisioning connection
(ChildProvisioningConnectionString).
Hangfire, Quartz.NET and other hosts work the same way: call ISyncOrchestrator.RunAsync from
your scheduler. Overlapping runs are safe, also across several instances.
How changes are found
| Strategy | Used when | Deletes reach the child |
|---|---|---|
| Change Tracking | SQL Server Change Tracking is on for the table | on every run |
| RowVersion | the table has a rowversion column |
at the delete check, hourly by default |
| Timestamp | the table has a UTC datetime column updated on every change (default LastUpdate) |
at the delete check |
| Full re-scan | none of the above, and the table has up to 50,000 rows | at the delete check |
Documentation
- Overview and guides
- Manual mode, step by step
- Auto mode, step by step
- Run it in your own app: background service, Hangfire, Quartz.NET
- Every setting, with examples
- Identities, rights and troubleshooting
- How each strategy finds changes
- Known limitations
- Changelog
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Data.SqlClient (>= 7.0.2)
- Microsoft.Data.SqlClient.Extensions.Azure (>= 7.0.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- System.Security.Cryptography.Pkcs (>= 10.0.13)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fixes the quick start in projects created from the template: in 0.5.1 it stopped when publishing
the Function. The library and the scaffold tool are unchanged apart from the version.
### Fixed
- The quick start in a project created from the `smarttablesync-azure` template stopped at
publishing the Function ("Can't determine project language from files"): `func` read the
runtime from `local.settings.json`, which such a project, like a fresh clone, doesn't have.
`deploy.ps1` and the demo's `run-demo.ps1` now pass `--dotnet-isolated`.
### Changed
- Turning on Change Tracking is now the first step of the quick start, in the README's *Get
started*, the NuGet guide and the template's READMEs.
### Upgrading
Nothing to change in the databases or settings. For a project created from the 0.5.1 template,
either add `--dotnet-isolated` to the `func azure functionapp publish` line in
`quickstart/deploy.ps1`, or run `dotnet new update` and create the project again.
### Tested
- Both ways in the README's *Get started*, from nuget.org in empty folders:
- **Own app:** a worker with the SmartTableSync package and SQL Server in Docker, with Change
Tracking turned on as the guide says. The first run created the child table and copied
1,000 rows; after updates, an insert and a delete in the parent, the next run synced 11 rows
and 1 delete.
- **Azure Function:** the template, Change Tracking turned on as the guide says, and
`deploy.ps1` with connection strings on two Azure SQL databases. The dry run, the setup
(Terraform, publishing the Function, the first sync: 500 and 300 rows), `-SyncNow` after
updates, inserts and a delete in the parent, and `-Destroy` all completed, with the child
matching the parent row for row.
- Unit and integration tests (298 and 72) pass.
Full changelog: https://github.com/Sidorus/SmartTableSync/blob/main/CHANGELOG.md