Sample code for 30+ languages & platforms
SQL Server 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 SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @iTmp1 int
    DECLARE @iTmp2 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @sTmp1 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  StringBuilder compares text by value in every generated language.
    DECLARE @textCompare int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @textCompare OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Assumes Chilkat is unlocked. See Global Unlock Sample.
    SELECT @success = 0
    DECLARE @config int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @config OUT

    EXEC sp_OASetProperty @config, 'Strict', 1
    EXEC sp_OAMethod @config, 'LoadFile', @success OUT, 'qa_data/azure/storage.json'
    IF @success <> 1
      BEGIN

        PRINT 'Could not load private Azure configuration.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        RETURN
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @sameText1 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText1 OUT, '', 1
    EXEC sp_OAMethod @config, 'JsonTypeOf', @iTmp0 OUT, 'account'
    IF (@iTmp0 <> 1) or (@sameText1 = 1)
      BEGIN

        PRINT 'Supply the storage account name.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        RETURN
      END
    --  access_key is the base64 account key, not a connection string or SAS.
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'access_key'
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @sameText2 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText2 OUT, '', 1
    EXEC sp_OAMethod @config, 'JsonTypeOf', @iTmp0 OUT, 'access_key'
    IF (@iTmp0 <> 1) or (@sameText2 = 1)
      BEGIN

        PRINT 'Supply the base64 account access key.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        RETURN
      END
    DECLARE @accountText int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @accountText OUT

    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
    EXEC sp_OAMethod @accountText, 'Append', @success OUT, @sTmp0
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        RETURN
      END
    EXEC sp_OAGetProperty @accountText, 'Length', @iTmp0 OUT
    EXEC sp_OAGetProperty @accountText, 'Length', @iTmp1 OUT
    IF (@iTmp0 < 3) or (@iTmp1 > 24)
      BEGIN

        PRINT 'Storage account names need 3-24 lowercase letters or digits.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        RETURN
      END
    DECLARE @allowedAccountChars int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @allowedAccountChars OUT

    EXEC sp_OAMethod @allowedAccountChars, 'Append', @success OUT, 'abcdefghijklmnopqrstuvwxyz0123456789'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        RETURN
      END
    DECLARE @charIndex int
    SELECT @charIndex = 0
    EXEC sp_OAGetProperty @accountText, 'Length', @iTmp0 OUT
    WHILE (@charIndex < @iTmp0)
      BEGIN
        EXEC sp_OAMethod @accountText, 'GetRange', @sTmp0 OUT, @charIndex, 1, 0
        EXEC sp_OAMethod @allowedAccountChars, 'Contains', @iTmp0 OUT, @sTmp0, 1
        IF @iTmp0 <> 1
          BEGIN

            PRINT 'Storage account names need lowercase letters or digits.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            RETURN
          END
        SELECT @charIndex = @charIndex + 1
      END
    DECLARE @endpoint int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @endpoint OUT

    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
    EXEC sp_OAMethod @endpoint, 'Append', @success OUT, @sTmp0
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        RETURN
      END
    EXEC sp_OAMethod @endpoint, 'Append', @success OUT, '.table.core.windows.net'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        RETURN
      END
    --  Table names contain only letters and digits and are case-insensitive.
    --  Entity PartitionKey and RowKey values are case-sensitive.
    DECLARE @resourcePath nvarchar(4000)
    SELECT @resourcePath = '/ExampleCustomers()'
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT

    EXEC sp_OASetProperty @rest, 'ConnectTimeoutMs', 20000
    EXEC sp_OASetProperty @rest, 'IdleTimeoutMs', 60000
    DECLARE @azAuth int
    EXEC @hr = sp_OACreate 'Chilkat.AuthAzureStorage', @azAuth OUT

    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
    EXEC sp_OASetProperty @azAuth, 'Account', @sTmp0
    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'access_key'
    EXEC sp_OASetProperty @azAuth, 'AccessKey', @sTmp0
    EXEC sp_OASetProperty @azAuth, 'Service', 'Table'
    EXEC sp_OASetProperty @azAuth, 'Scheme', 'SharedKey'
    EXEC sp_OASetProperty @azAuth, 'XMsVersion', '2026-04-06'
    EXEC sp_OAMethod @rest, 'SetAuthAzureStorage', @success OUT, @azAuth
    IF @success <> 1
      BEGIN

        PRINT 'Could not configure Shared Key signing.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        RETURN
      END
    DECLARE @connection int
    EXEC @hr = sp_OACreate 'Chilkat.Socket', @connection OUT

    EXEC sp_OASetProperty @connection, 'RequireSslCertVerify', 1
    EXEC sp_OASetProperty @connection, 'MaxReadIdleMs', 60000
    EXEC sp_OASetProperty @connection, 'MaxSendIdleMs', 60000
    EXEC sp_OAMethod @endpoint, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @connection, 'Connect', @success OUT, @sTmp0, 443, 1, 20000
    IF @success <> 1
      BEGIN

        PRINT 'TLS connection failed; inspect diagnostics privately.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    --  Do not replay a write automatically after losing its response.
    EXEC sp_OAMethod @rest, 'UseConnection', @success OUT, @connection, 0
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    DECLARE @responseText nvarchar(4000)

    DECLARE @result int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @result OUT

    EXEC sp_OASetProperty @result, 'Strict', 1
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'DataServiceVersion', '3.0;NetFx'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'MaxDataServiceVersion', '3.0;NetFx'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/json'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Accept', 'application/json;odata=minimalmetadata'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    --  Single-caller, one-page-per-run example. Archive table-page.json before the next run.
    DECLARE @files int
    EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @files OUT

    EXEC sp_OAMethod @files, 'FileExists', @iTmp0 OUT, 'qa_output/table-page.json'
    IF @iTmp0 = 1
      BEGIN

        PRINT 'Previous page output exists; process and archive it before continuing.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        RETURN
      END
    DECLARE @checkpoint int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @checkpoint OUT

    EXEC sp_OASetProperty @checkpoint, 'Strict', 1
    DECLARE @nextPartition nvarchar(4000)
    SELECT @nextPartition = ''
    DECLARE @nextRow nvarchar(4000)
    SELECT @nextRow = ''
    EXEC sp_OAMethod @files, 'FileExists', @iTmp0 OUT, 'qa_data/azure/table-checkpoint.json'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @checkpoint, 'LoadFile', @success OUT, 'qa_data/azure/table-checkpoint.json'
        IF @success <> 1
          BEGIN

            PRINT 'Invalid checkpoint; do not silently restart.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
        EXEC sp_OAMethod @textCompare, 'Clear', NULL
        EXEC sp_OAMethod @checkpoint, 'StringOf', @sTmp0 OUT, 'path'
        EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
        DECLARE @sameText3 int
        EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText3 OUT, @resourcePath, 1
        EXEC sp_OAMethod @textCompare, 'Clear', NULL
        EXEC sp_OAMethod @checkpoint, 'StringOf', @sTmp0 OUT, 'filter'
        EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
        DECLARE @sameText4 int
        EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText4 OUT, 'PartitionKey eq ''customers-west''', 1
        EXEC sp_OAMethod @textCompare, 'Clear', NULL
        EXEC sp_OAMethod @checkpoint, 'StringOf', @sTmp0 OUT, 'select'
        EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
        DECLARE @sameText5 int
        EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText5 OUT, 'PartitionKey,RowKey,Address,NumberOfOrders', 1
        EXEC sp_OAMethod @textCompare, 'Clear', NULL
        EXEC sp_OAMethod @checkpoint, 'StringOf', @sTmp0 OUT, 'top'
        EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
        DECLARE @sameText6 int
        EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText6 OUT, '100', 1
        EXEC sp_OAMethod @textCompare, 'Clear', NULL
        EXEC sp_OAMethod @checkpoint, 'StringOf', @sTmp0 OUT, 'version'
        EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
        DECLARE @sameText7 int
        EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText7 OUT, '2026-04-06', 1
        EXEC sp_OAMethod @checkpoint, 'StringOf', @sTmp0 OUT, 'account'
        EXEC sp_OAMethod @config, 'StringOf', @sTmp1 OUT, 'account'
        IF (@sTmp0 <> @sTmp1) or (@sameText3 <> 1) or (@sameText4 <> 1) or (@sameText5 <> 1) or (@sameText6 <> 1) or (@sameText7 <> 1)
          BEGIN

            PRINT 'Checkpoint belongs to a different account or query.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
        EXEC sp_OAMethod @checkpoint, 'JsonTypeOf', @iTmp0 OUT, 'complete'
        EXEC sp_OAMethod @checkpoint, 'JsonTypeOf', @iTmp1 OUT, 'partition'
        EXEC sp_OAMethod @checkpoint, 'JsonTypeOf', @iTmp2 OUT, 'row'
        IF (@iTmp0 <> 5) or (@iTmp1 <> 1) or (@iTmp2 <> 1)
          BEGIN

            PRINT 'Checkpoint fields are invalid.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
        EXEC sp_OAMethod @checkpoint, 'BoolOf', @iTmp0 OUT, 'complete'
        IF @iTmp0 = 1
          BEGIN

            PRINT 'Query already complete.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
        EXEC sp_OAMethod @checkpoint, 'StringOf', @nextPartition OUT, 'partition'
        EXEC sp_OAMethod @checkpoint, 'StringOf', @nextRow OUT, 'row'
        EXEC sp_OAMethod @textCompare, 'Clear', NULL
        EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @nextPartition
        DECLARE @sameText8 int
        EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText8 OUT, '', 1
        IF @sameText8 = 1
          BEGIN

            PRINT 'Incomplete checkpoint has no continuation token.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, '$filter', 'PartitionKey eq ''customers-west'''
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, '$select', 'PartitionKey,RowKey,Address,NumberOfOrders'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, '$top', '100'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @nextPartition
    DECLARE @sameText9 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText9 OUT, '', 1
    IF @sameText9 <> 1
      BEGIN
        EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'NextPartitionKey', @nextPartition
        IF @success <> 1
          BEGIN

            PRINT 'Could not prepare the request.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @nextRow
    DECLARE @sameText10 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText10 OUT, '', 1
    IF @sameText10 <> 1
      BEGIN
        EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'NextRowKey', @nextRow
        IF @success <> 1
          BEGIN

            PRINT 'Could not prepare the request.'
            EXEC @hr = sp_OADestroy @textCompare
            EXEC @hr = sp_OADestroy @config
            EXEC @hr = sp_OADestroy @accountText
            EXEC @hr = sp_OADestroy @allowedAccountChars
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @azAuth
            EXEC @hr = sp_OADestroy @connection
            EXEC @hr = sp_OADestroy @result
            EXEC @hr = sp_OADestroy @files
            EXEC @hr = sp_OADestroy @checkpoint
            RETURN
          END
      END
    EXEC sp_OAMethod @rest, 'FullRequestNoBody', @responseText OUT, 'GET', @resourcePath
    EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN

        PRINT 'Request did not complete; inspect the target before retrying a write.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
        PRINT 'HTTP status: ' + @iTmp0

        EXEC sp_OAMethod @rest, 'ResponseHdrByName', @sTmp0 OUT, 'x-ms-request-id'
        PRINT 'Request ID: ' + @sTmp0
        --  404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
        --  Keep response bodies private. Reconcile uncertain writes before retrying.
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @result, 'Load', @success OUT, @responseText
    IF @success <> 1
      BEGIN

        PRINT 'Expected well-formed JSON.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @result, 'JsonTypeOf', @iTmp0 OUT, 'value'
    IF @iTmp0 <> 4
      BEGIN

        PRINT 'Missing entity/table array.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    DECLARE @followingPartition nvarchar(4000)
    EXEC sp_OAMethod @rest, 'ResponseHdrByName', @followingPartition OUT, 'x-ms-continuation-NextPartitionKey'
    DECLARE @followingRow nvarchar(4000)
    EXEC sp_OAMethod @rest, 'ResponseHdrByName', @followingRow OUT, 'x-ms-continuation-NextRowKey'
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingPartition
    DECLARE @sameText11 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText11 OUT, 'null', 1
    IF @sameText11 = 1
      BEGIN
        SELECT @followingPartition = ''
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingRow
    DECLARE @sameText12 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText12 OUT, 'null', 1
    IF @sameText12 = 1
      BEGIN
        SELECT @followingRow = ''
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingPartition
    DECLARE @sameText13 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText13 OUT, '', 1
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingRow
    DECLARE @sameText14 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText14 OUT, '', 1
    IF (@sameText13 = 1) and (@sameText14 <> 1)
      BEGIN

        PRINT 'Malformed continuation.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingPartition
    DECLARE @sameText15 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText15 OUT, '', 1
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingPartition
    DECLARE @sameText16 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText16 OUT, @nextPartition, 1
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingRow
    DECLARE @sameText17 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText17 OUT, @nextRow, 1
    IF (@sameText15 <> 1) and (@sameText16 = 1) and (@sameText17 = 1)
      BEGIN

        PRINT 'Service repeated the current checkpoint.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    --  Save the page before advancing its checkpoint. Failures can cause replay, never intentional skipping.
    EXEC sp_OAMethod @result, 'WriteFile', @success OUT, 'qa_output/table-page.json'
    IF @success <> 1
      BEGIN

        PRINT 'Could not save private page output.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'account', @sTmp0
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'path', @resourcePath
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'filter', 'PartitionKey eq ''customers-west'''
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'select', 'PartitionKey,RowKey,Address,NumberOfOrders'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'top', '100'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'version', '2026-04-06'
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'partition', @followingPartition
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateString', @success OUT, 'row', @followingRow
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    DECLARE @completed int
    SELECT @completed = 0
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @followingPartition
    DECLARE @sameText18 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText18 OUT, '', 1
    IF @sameText18 = 1
      BEGIN
        SELECT @completed = 1
      END
    EXEC sp_OAMethod @checkpoint, 'UpdateBool', @success OUT, 'complete', @completed
    IF @success <> 1
      BEGIN

        PRINT 'Could not prepare the request.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END
    EXEC sp_OAMethod @checkpoint, 'WriteFile', @success OUT, 'qa_data/azure/table-checkpoint.json'
    IF @success <> 1
      BEGIN

        PRINT 'Page saved but checkpoint write failed. Preserve the page and reconcile before resuming.'
        EXEC @hr = sp_OADestroy @textCompare
        EXEC @hr = sp_OADestroy @config
        EXEC @hr = sp_OADestroy @accountText
        EXEC @hr = sp_OADestroy @allowedAccountChars
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @azAuth
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @files
        EXEC @hr = sp_OADestroy @checkpoint
        RETURN
      END

    PRINT 'Page and continuation checkpoint saved privately.'

    EXEC @hr = sp_OADestroy @textCompare
    EXEC @hr = sp_OADestroy @config
    EXEC @hr = sp_OADestroy @accountText
    EXEC @hr = sp_OADestroy @allowedAccountChars
    EXEC @hr = sp_OADestroy @endpoint
    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @azAuth
    EXEC @hr = sp_OADestroy @connection
    EXEC @hr = sp_OADestroy @result
    EXEC @hr = sp_OADestroy @files
    EXEC @hr = sp_OADestroy @checkpoint


END
GO