Text and CSV files¶
| DBMS Type | Text |
| Driver | SQDR Text driver, installed with SQDR: there's nothing to install. |
| Connection string | The Text template: Database=C:\mydest;AllowUpdateAndDelete=1. See Connection string. |
| Apply methods | Batch and Sequence (no Merge) |
| Indexes | None |
What the destination is. A folder on the computer where the Replicator Service runs, named by Database=; each
destination table is a file in it. The driver also keeps a file QETXT.INI there, which describes the tables: don't
edit or delete it while subscriptions use the folder.
Prepare the folder. Create the folder, and let the account the Replicator Service runs as (for example Local System, or a domain user) create, change and delete files in it.
Docker
The SQDR container includes the SQDR Text driver. Database= is a path inside the container: use a folder on one
of its volumes (see Volumes), or the files are lost when the container is
recreated.
How it's written.
- The Replicator Service turns on autocommit for Text connections, so each statement is committed as it runs: a failed run can leave some rows written.
- Truncate table before replication runs
DELETE FROMthe table, because the driver has noTRUNCATE. - For a history of changes in files, use Archive all DML Activity in the members' apply options: every change is appended as a new row, and nothing has to be updated or deleted.
Connection string¶
Database= is the folder, and each table is a file in it. The template,
Database=C:\mydest;AllowUpdateAndDelete=1, writes to C:\mydest. Set the file format with the driver's keywords:
| Keyword | What it does |
|---|---|
AllowUpdateAndDelete=1 |
Lets the Replicator Service update and delete rows in the files, not only insert them. Needed for incremental groups that update or delete rows, and to empty a file before a baseline. |
TableType=Character;Delimiter=\| |
Character-delimited files, with \| between fields. |
DataFileExtension=CSV |
The extension of the files. |
FirstLineNames=1 |
Writes the column names on the first line. |
For example, files with the extension .csv, fields separated by |, and column names on the first line:
Database=C:\transfer;AllowUpdateAndDelete=1;TableType=Character;Delimiter=|;DataFileExtension=CSV;FirstLineNames=1
Upload the files to Azure Data Lake Storage Gen2¶
Azure Data Lake Storage Gen2 (ADLS Gen2) has no ODBC driver, so it can't be a destination. To land replicated data there, either stream the changes through Kafka to Azure Event Hubs and turn on the event hub's Capture, or write CSV files with a Text destination and upload them on a schedule with PowerShell, as described here.
How it works. An incremental group writes every change as a new row to one CSV file per table. A Windows scheduled task runs a PowerShell script, for example every hour, which:
- pauses the incremental group, copies the CSV files to a work folder, empties the active files, and resumes the group, so that the group is paused only for a moment;
- renames each non-empty file in the work folder to
<table><timestamp>.csvand uploads it to ADLS Gen2 with the Az.Storage PowerShell module; - moves a file that couldn't be uploaded to a holding folder, so that nothing is lost.
Stelo provides sample scripts for this in
sqdr_azure.zip: parms.ps1 (your settings, documented in its
comments), setup_azure.ps1 (run once: checks the connection and can create the container and directory),
sqdr_azure.ps1 (the transfer) and sqdr_azure.cmd (runs it with a log file, for the scheduled task). Adapt them to
your needs, for example to filter files or to sign in with Microsoft Entra ID instead of the storage account key.
What you need:
-
On the Stelo VM: PowerShell 5.1 or later (
$PSVersionTable.PSVersion), .NET Framework 4.7.2 or later, and the Az.Storage module, installed from an elevated PowerShell window:# Older Windows versions only: use TLS 1.2 and install NuGet first [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 Install-PackageProvider -Name NuGet -Force Install-Module Az.Storage -Repository PSGallery -Force -
In Azure: a storage account with hierarchical namespace enabled, its name and access key, and the container and directory to upload to (the setup script, or the upload itself, can create them if the key allows it).
Set up SQDR:
-
Create a Text destination whose folder is the one the script reads (its source folder in
parms.ps1), for example:Database=C:\Scripts\Transfer;TableType=Character;Delimiter=|;DataFileExtension=CSV;FirstLineNames=1Without
FirstLineNames=1, set$FirstLineNames="0"inparms.ps1.AllowUpdateAndDelete=1isn't needed when every member archives its changes; add it if saving a subscription should re-create its file, for example to add columns. -
Create the incremental group, and on its Advanced tab set the Subscription Wizard Defaults to Archive all DML Activity.
- Add the members with Insert Subscription, with Create if does not exist, else use existing and Append replicated rows to existing data. For changes only, without the baselines' rows, choose Null synchronization - DDL Only.
- Add capture metadata columns so that each row says what
happened, for example
@TYPEasVARCHAR(1)and@TXand@SEQasVARCHAR(20). Make them nullable: they're empty in baseline rows.
Set up the scripts:
- Expand the zip file, for example into
C:\Scripts, which creates the foldersTransfer(the files SQDR writes),Staging(the work folder) andHolding(files that failed to upload). In another folder, also changeDIRinsqdr_azure.ps1and the folders inparms.ps1. - Edit
parms.ps1: the storage account, key, container and directory, the folders, and the incremental group. - Run
setup_azure.ps1, then testsqdr_azure.ps1from an elevated PowerShell window (pausing and resuming the group needs administrator rights). - In Task Scheduler, create a task that runs
sqdr_azure.cmd(orpowershell -F C:\Scripts\sqdr_azure.ps1) at the interval you want, as SYSTEM, with Run whether user is logged on or not. Add a second task that deletes old log files.
If a run can take longer than the interval, give each run its own work folder (for example named with the date and hour), and clean those up.
For errors from the scripts, see Troubleshooting › Text files uploaded to Azure Data Lake Storage.