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

Azure Table: Insert an Entity with Typed Properties

See more Azure Table Service Examples

Insert into an existing table using Prefer: return-no-content. Requires HTTP 204, avoids parsing its empty body, and captures the ETag for later conditional writes. Insert is create-only; an existing PartitionKey/RowKey pair produces a conflict.

Includes explicit Edm.Guid, Edm.DateTime, and Edm.Int64 annotations. The Int64 is serialized as a string beyond JavaScript's exact integer range, preserving its digits in every generated language. The timestamp is server-managed. AmountDue demonstrates Edm.Double, which is not exact decimal currency. See Table JSON types.

Uses Chilkat.Rest and AuthAzureStorage with Table-specific Shared Key signing. Load a private qa_data/azure/storage.json containing string fields account and access_key (the base64 account key, not a connection string or SAS). Keep this file outside public web content and source control. Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table.

Pins x-ms-version: 2026-04-06, Microsoft's documented fully deployed Storage version at review time, and sends OData 3.0 headers. Older supported versions are not automatically obsolete. See Storage versioning and OData headers.

Microsoft recommends Microsoft Entra ID authorization, preferably managed identity where available. This example retains its existing Shared Key authentication pattern; use it only when account policy permits. TLS certificates are verified, timeouts are bounded, and diagnostic dumps and entity payloads are not printed. A lost response can leave a write's outcome uncertain: inspect the target before retrying.

Microsoft insert entity 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 @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
    --  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 @responseBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @responseBody OUT

    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 @responseBody
        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 @responseBody
        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 @responseBody
        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 @responseBody
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Prefer', 'return-no-content'
    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 @responseBody
        RETURN
      END
    --  The table must already exist. Change resourcePath above to your table's name.
    --  PartitionKey + RowKey uniquely identify the entity. Inserting an existing pair returns 409.
    --  Adapt these fixed sample values; keys cannot contain /, backslash, #, ?, or control characters.
    --  Timestamp is server-managed; do not put it in the request.
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'PartitionKey', '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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'RowKey', 'customer-001'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'Address', 'Mountain View'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'Age', 23
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'AmountDue', '200.23'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    --  AmountDue is Edm.Double, not exact decimal currency. Use an integer minor-unit design for exact money.
    --  Quote the whole JSON path so @odata.type is a literal property name.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '"CustomerCode@odata.type"', 'Edm.Guid'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CustomerCode', 'c9da6455-213d-42c9-9a79-3e9149a57833'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    --  Quote the whole JSON path so @odata.type is a literal property name.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '"CustomerSince@odata.type"', 'Edm.DateTime'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CustomerSince', '2008-07-10T00:00:00Z'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    --  Quote the whole JSON path so @odata.type is a literal property name.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '"NumberOfOrders@odata.type"', 'Edm.Int64'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'NumberOfOrders', '9007199254740993'
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'IsActive', 1
    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 @responseBody
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    DECLARE @requestBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @requestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @requestBody
    IF @success <> 1
      BEGIN

        PRINT 'Could not serialize the JSON 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 @responseBody
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @requestBody
        RETURN
      END
    EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', @resourcePath, @requestBody, @responseBody
    IF @success <> 1
      BEGIN

        PRINT 'Request did not complete; check the target 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 @responseBody
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @requestBody
        RETURN
      END
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 204
      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
        --  A conflict is not success. Do not replay or convert this request into an upsert.
        EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
        IF @iTmp0 = 409
          BEGIN

            PRINT 'The table/entity may already exist, or a table may still be deleting. Inspect its state.'
          END
        --  Table errors may be in an OData JSON body instead of x-ms-error-code.
        --  Keep the body and LastErrorText private; they can contain entity data.
        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 @responseBody
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @requestBody
        RETURN
      END
    --  HTTP 204 has no JSON body. Preserve this ETag exactly, including W/ and quotes,
    --  for a later conditional update or delete with If-Match.
    DECLARE @entityEtag nvarchar(4000)
    EXEC sp_OAMethod @rest, 'ResponseHdrByName', @entityEtag OUT, 'ETag'
    EXEC sp_OAMethod @textCompare, 'Clear', NULL
    EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @entityEtag
    DECLARE @sameText3 int
    EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText3 OUT, '', 1
    IF @sameText3 = 1
      BEGIN

        PRINT 'Entity inserted, but ETag is missing. Retrieve the entity before a conditional write; do not repeat the insert.'
        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 @responseBody
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @requestBody
        RETURN
      END

    PRINT 'Entity inserted.'

    PRINT 'ETag: ' + @entityEtag

    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 @responseBody
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @requestBody


END
GO