Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.6.0+

Azure Table: Save and Resume an Entity Query

See more Azure Table Service Examples

Fetches one page per invocation and saves private JSON plus a checkpoint bound to the account, collection path, filter, projection, page size and API version. Refuses to overwrite an unprocessed page. Process/archive qa_output/table-page.json before the next run; keep table-checkpoint.json until completion.

This demonstrates at-least-once processing, not an atomic transaction between output and checkpoint. A crash or failed checkpoint write can replay a page; deduplicate by entity identity/version. A malformed checkpoint stops instead of restarting. Use a single caller, protect files, and use transactional durable state for stronger guarantees. Table contents can change during enumeration.

Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.

HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.

Microsoft reference.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // StringBuilder compares text by value in every generated language.
  final textCompare = CkStringBuilder();
  // Assumes Chilkat is unlocked. See Global Unlock Sample.
  final config = CkJsonObject();
  config.strict = true;
  try {
    config.loadFile('qa_data/azure/storage.json');
  } on ChilkatException {
    print('Could not load private Azure configuration.');
    return;
  }

  textCompare.clear();
  textCompare.setString(config.stringOf('account'));
  final sameText1 = textCompare.contentsEqual('', true);
  if ((config.jsonTypeOf('account') != 1) || (sameText1)) {
    print('Supply the storage account name.');
    return;
  }

  // access_key is the base64 account key, not a connection string or SAS.
  textCompare.clear();
  textCompare.setString(config.stringOf('access_key'));
  final sameText2 = textCompare.contentsEqual('', true);
  if ((config.jsonTypeOf('access_key') != 1) || (sameText2)) {
    print('Supply the base64 account access key.');
    return;
  }

  final accountText = CkStringBuilder();
  try {
    accountText.append(config.stringOf('account'));
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  if ((accountText.length < 3) || (accountText.length > 24)) {
    print('Storage account names need 3-24 lowercase letters or digits.');
    return;
  }

  final allowedAccountChars = CkStringBuilder();
  try {
    allowedAccountChars.append('abcdefghijklmnopqrstuvwxyz0123456789');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  var charIndex = 0;
  while (charIndex < accountText.length) {
    if (!allowedAccountChars.contains(accountText.getRange(charIndex, 1, false), true)) {
      print('Storage account names need lowercase letters or digits.');
      return;
    }

    charIndex++;
  }

  final endpoint = CkStringBuilder();
  try {
    endpoint.append(config.stringOf('account'));
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    endpoint.append('.table.core.windows.net');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  // Table names contain only letters and digits and are case-insensitive.
  // Entity PartitionKey and RowKey values are case-sensitive.
  final resourcePath = '/ExampleCustomers()';
  final rest = CkRest();
  rest.connectTimeoutMs = 20000;
  rest.idleTimeoutMs = 60000;
  final azAuth = CkAuthAzureStorage();
  azAuth.account = config.stringOf('account');
  azAuth.accessKey = config.stringOf('access_key');
  azAuth.service = 'Table';
  azAuth.scheme = 'SharedKey';
  azAuth.xMsVersion = '2026-04-06';
  try {
    rest.setAuthAzureStorage(azAuth);
  } on ChilkatException {
    print('Could not configure Shared Key signing.');
    return;
  }

  final connection = CkSocket();
  connection.requireSslCertVerify = true;
  connection.maxReadIdleMs = 60000;
  connection.maxSendIdleMs = 60000;
  try {
    connection.connect(endpoint.getAsString(), 443, true, 20000);
  } on ChilkatException {
    print('TLS connection failed; inspect diagnostics privately.');
    return;
  }

  // Do not replay a write automatically after losing its response.
  try {
    rest.useConnection(connection, false);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  var responseText = '';
  final result = CkJsonObject();
  result.strict = true;
  try {
    rest.addHeader('DataServiceVersion', '3.0;NetFx');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addHeader('MaxDataServiceVersion', '3.0;NetFx');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addHeader('Content-Type', 'application/json');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addHeader('Accept', 'application/json;odata=minimalmetadata');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  // Single-caller, one-page-per-run example. Archive table-page.json before the next run.
  final files = CkFileAccess();
  if (files.fileExists('qa_output/table-page.json')) {
    print('Previous page output exists; process and archive it before continuing.');
    return;
  }

  final checkpoint = CkJsonObject();
  checkpoint.strict = true;
  var nextPartition = '';
  var nextRow = '';
  if (files.fileExists('qa_data/azure/table-checkpoint.json')) {
    try {
      checkpoint.loadFile('qa_data/azure/table-checkpoint.json');
    } on ChilkatException {
      print('Invalid checkpoint; do not silently restart.');
      return;
    }

    textCompare.clear();
    textCompare.setString(checkpoint.stringOf('path'));
    final sameText3 = textCompare.contentsEqual(resourcePath, true);
    textCompare.clear();
    textCompare.setString(checkpoint.stringOf('filter'));
    final sameText4 = textCompare.contentsEqual('PartitionKey eq \'customers-west\'', true);
    textCompare.clear();
    textCompare.setString(checkpoint.stringOf('select'));
    final sameText5 = textCompare.contentsEqual('PartitionKey,RowKey,Address,NumberOfOrders', true);
    textCompare.clear();
    textCompare.setString(checkpoint.stringOf('top'));
    final sameText6 = textCompare.contentsEqual('100', true);
    textCompare.clear();
    textCompare.setString(checkpoint.stringOf('version'));
    final sameText7 = textCompare.contentsEqual('2026-04-06', true);
    if ((checkpoint.stringOf('account') != config.stringOf('account')) || ((!sameText3) || ((!sameText4) || ((!sameText5) || ((!sameText6) || (!sameText7)))))) {
      print('Checkpoint belongs to a different account or query.');
      return;
    }

    if ((checkpoint.jsonTypeOf('complete') != 5) || ((checkpoint.jsonTypeOf('partition') != 1) || (checkpoint.jsonTypeOf('row') != 1))) {
      print('Checkpoint fields are invalid.');
      return;
    }

    if (checkpoint.boolOf('complete')) {
      print('Query already complete.');
      return;
    }

    nextPartition = checkpoint.stringOf('partition');
    nextRow = checkpoint.stringOf('row');
    textCompare.clear();
    textCompare.setString(nextPartition);
    final sameText8 = textCompare.contentsEqual('', true);
    if (sameText8) {
      print('Incomplete checkpoint has no continuation token.');
      return;
    }
  }

  try {
    rest.addQueryParam('\$filter', 'PartitionKey eq \'customers-west\'');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addQueryParam('\$select', 'PartitionKey,RowKey,Address,NumberOfOrders');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addQueryParam('\$top', '100');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  textCompare.clear();
  textCompare.setString(nextPartition);
  final sameText9 = textCompare.contentsEqual('', true);
  if (!sameText9) {
    try {
      rest.addQueryParam('NextPartitionKey', nextPartition);
    } on ChilkatException {
      print('Could not prepare the request.');
      return;
    }
  }

  textCompare.clear();
  textCompare.setString(nextRow);
  final sameText10 = textCompare.contentsEqual('', true);
  if (!sameText10) {
    try {
      rest.addQueryParam('NextRowKey', nextRow);
    } on ChilkatException {
      print('Could not prepare the request.');
      return;
    }
  }

  try {
    responseText = rest.fullRequestNoBody('GET', resourcePath);
  } on ChilkatException {
    print('Request did not complete; inspect the target before retrying a write.');
    return;
  }

  if (rest.responseStatusCode != 200) {
    print('HTTP status: ${rest.responseStatusCode}');
    print('Request ID: ${rest.responseHdrByName('x-ms-request-id')}');
    // 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
    // Keep response bodies private. Reconcile uncertain writes before retrying.
    return;
  }

  try {
    result.load(responseText);
  } on ChilkatException {
    print('Expected well-formed JSON.');
    return;
  }

  if (result.jsonTypeOf('value') != 4) {
    print('Missing entity/table array.');
    return;
  }

  var followingPartition = rest.responseHdrByName('x-ms-continuation-NextPartitionKey');
  var followingRow = rest.responseHdrByName('x-ms-continuation-NextRowKey');
  textCompare.clear();
  textCompare.setString(followingPartition);
  final sameText11 = textCompare.contentsEqual('null', true);
  if (sameText11) {
    followingPartition = '';
  }

  textCompare.clear();
  textCompare.setString(followingRow);
  final sameText12 = textCompare.contentsEqual('null', true);
  if (sameText12) {
    followingRow = '';
  }

  textCompare.clear();
  textCompare.setString(followingPartition);
  final sameText13 = textCompare.contentsEqual('', true);
  textCompare.clear();
  textCompare.setString(followingRow);
  final sameText14 = textCompare.contentsEqual('', true);
  if ((sameText13) && (!sameText14)) {
    print('Malformed continuation.');
    return;
  }

  textCompare.clear();
  textCompare.setString(followingPartition);
  final sameText15 = textCompare.contentsEqual('', true);
  textCompare.clear();
  textCompare.setString(followingPartition);
  final sameText16 = textCompare.contentsEqual(nextPartition, true);
  textCompare.clear();
  textCompare.setString(followingRow);
  final sameText17 = textCompare.contentsEqual(nextRow, true);
  if ((!sameText15) && ((sameText16) && (sameText17))) {
    print('Service repeated the current checkpoint.');
    return;
  }

  // Save the page before advancing its checkpoint. Failures can cause replay, never intentional skipping.
  try {
    result.writeFile('qa_output/table-page.json');
  } on ChilkatException {
    print('Could not save private page output.');
    return;
  }

  try {
    checkpoint.updateString('account', config.stringOf('account'));
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('path', resourcePath);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('filter', 'PartitionKey eq \'customers-west\'');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('select', 'PartitionKey,RowKey,Address,NumberOfOrders');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('top', '100');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('version', '2026-04-06');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('partition', followingPartition);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.updateString('row', followingRow);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  var completed = false;
  textCompare.clear();
  textCompare.setString(followingPartition);
  final sameText18 = textCompare.contentsEqual('', true);
  if (sameText18) {
    completed = true;
  }

  try {
    checkpoint.updateBool('complete', completed);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    checkpoint.writeFile('qa_data/azure/table-checkpoint.json');
  } on ChilkatException {
    print('Page saved but checkpoint write failed. Preserve the page and reconcile before resuming.');
    return;
  }

  print('Page and continuation checkpoint saved privately.');
}