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

Azure Table: Read an Entity with a Supplied Table SAS

See more Azure Table Service Examples

Loads table-sas.txt created by the related service-SAS example, or supplied by a trusted issuer. storage.json needs only account. Sends no Authorization header or account key; Chilkat parses and encodes the token query once. The endpoint and entity path remain fixed by the application, not by the supplied token. A 403 may indicate expiry, insufficient permission, account policy or an entity outside the signed range.

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 @iTmp3 int
    DECLARE @iTmp4 int
    DECLARE @sTmp0 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
    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 @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 @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 @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 @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 @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 @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 @connection
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'x-ms-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 @connection
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    DECLARE @sasText int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sasText OUT

    EXEC sp_OAMethod @sasText, 'LoadFile', @success OUT, 'qa_data/azure/table-sas.txt', 'utf-8'
    IF @success <> 1
      BEGIN

        PRINT 'Could not read private SAS 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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        RETURN
      END
    EXEC sp_OAMethod @sasText, 'Trim', @success OUT
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        RETURN
      END
    EXEC sp_OAGetProperty @sasText, 'Length', @iTmp0 OUT
    EXEC sp_OAMethod @sasText, 'Contains', @iTmp1 OUT, '?', 1
    EXEC sp_OAMethod @sasText, 'Contains', @iTmp2 OUT, '#', 1
    EXEC sp_OAMethod @sasText, 'Contains', @iTmp3 OUT, CHAR(13), 1
    EXEC sp_OAMethod @sasText, 'Contains', @iTmp4 OUT, CHAR(10), 1
    IF (@iTmp0 = 0) or (@iTmp1 = 1) or (@iTmp2 = 1) or (@iTmp3 = 1) or (@iTmp4 = 1)
      BEGIN

        PRINT 'Expected a SAS query string without a leading ?, fragment, or line break.'
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        RETURN
      END
    EXEC sp_OAMethod @sasText, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @rest, 'AddQueryParams', @success OUT, @sTmp0
    IF @success <> 1
      BEGIN

        PRINT 'Could not parse SAS query parameters.'
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        RETURN
      END
    DECLARE @partitionKey nvarchar(4000)
    SELECT @partitionKey = 'customers-west'
    DECLARE @rowKey nvarchar(4000)
    SELECT @rowKey = 'customer-001'
    DECLARE @encodedPk int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @encodedPk OUT

    EXEC sp_OAMethod @encodedPk, 'Append', @success OUT, @partitionKey
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        RETURN
      END
    DECLARE @escapedencodedPk int
    EXEC sp_OAMethod @encodedPk, 'Replace', @escapedencodedPk OUT, '''', ''''''
    EXEC sp_OAMethod @encodedPk, 'Encode', @success OUT, 'url_rfc3986', 'utf-8'
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        RETURN
      END
    DECLARE @encodedRk int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @encodedRk OUT

    EXEC sp_OAMethod @encodedRk, 'Append', @success OUT, @rowKey
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        RETURN
      END
    DECLARE @escapedencodedRk int
    EXEC sp_OAMethod @encodedRk, 'Replace', @escapedencodedRk OUT, '''', ''''''
    EXEC sp_OAMethod @encodedRk, 'Encode', @success OUT, 'url_rfc3986', 'utf-8'
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        RETURN
      END
    --  Escape apostrophes for OData first, then percent-encode each key once.
    DECLARE @entityPath int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @entityPath OUT

    EXEC sp_OAMethod @entityPath, 'Append', @success OUT, '/ExampleCustomers(PartitionKey='''
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @encodedPk, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @entityPath, '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
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @entityPath, 'Append', @success OUT, ''',RowKey='''
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @encodedRk, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @entityPath, '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
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @entityPath, 'Append', @success OUT, ''')'
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @entityPath, 'GetAsString', @resourcePath OUT
    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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'PartitionKey'
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @sameText2 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText2 OUT, '', 1
    EXEC sp_OAMethod @result, 'JsonTypeOf', @iTmp0 OUT, 'PartitionKey'
    IF (@iTmp0 <> 1) or (@sameText2 = 1)
      BEGIN

        PRINT 'Missing string PartitionKey.'
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'RowKey'
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @sameText3 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText3 OUT, '', 1
    EXEC sp_OAMethod @result, 'JsonTypeOf', @iTmp0 OUT, 'RowKey'
    IF (@iTmp0 <> 1) or (@sameText3 = 1)
      BEGIN

        PRINT 'Missing string RowKey.'
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'PartitionKey'
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @sameText4 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText4 OUT, @partitionKey, 1
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'RowKey'
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @sameText5 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText5 OUT, @rowKey, 1
    IF (@sameText4 <> 1) or (@sameText5 <> 1)
      BEGIN

        PRINT 'Returned entity keys do not match.'
        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 @connection
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @sasText
        EXEC @hr = sp_OADestroy @encodedPk
        EXEC @hr = sp_OADestroy @encodedRk
        EXEC @hr = sp_OADestroy @entityPath
        RETURN
      END

    PRINT 'Entity retrieved with the supplied SAS.'

    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 @connection
    EXEC @hr = sp_OADestroy @result
    EXEC @hr = sp_OADestroy @sasText
    EXEC @hr = sp_OADestroy @encodedPk
    EXEC @hr = sp_OADestroy @encodedRk
    EXEC @hr = sp_OADestroy @entityPath


END
GO