Azure Table: Create a Read-Only Table Service SAS
See more Azure Table Service Examples
Generates a short-lived HTTPS-only account-key service SAS for ExampleCustomers, restricted to one partition and the inclusive lexical row range customer-001 through customer-099. Includes Table-specific spk/srk/epk/erk fields, lowercase canonical table name and tn. It grants entity reads, not table creation/deletion or policy administration. Respect stricter account SAS-expiration policies.
Writes a token without a leading question mark to private table-sas.txt, replacing a prior token. Anyone holding it can exercise its permissions until expiry; do not log it. This is an account-key Table service SAS, not a Blob user-delegation SAS.
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.
Chilkat SQL Server Downloads
-- 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 @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 @sas int
EXEC @hr = sp_OACreate 'Chilkat.AuthAzureSAS', @sas OUT
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'access_key'
EXEC sp_OASetProperty @sas, 'AccessKey', @sTmp0
EXEC sp_OASetProperty @sas, 'StringToSign', 'sp,st,se,resource,si,sip,spr,sv,spk,srk,epk,erk'
DECLARE @canonical int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @canonical OUT
EXEC sp_OAMethod @canonical, 'Append', @success OUT, '/table/'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
RETURN
END
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
EXEC sp_OAMethod @canonical, '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 @sas
EXEC @hr = sp_OADestroy @canonical
RETURN
END
EXEC sp_OAMethod @canonical, 'Append', @success OUT, '/examplecustomers'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
RETURN
END
EXEC sp_OAMethod @canonical, 'GetAsString', @sTmp0 OUT
EXEC sp_OAMethod @sas, 'SetNonTokenParam', @success OUT, 'resource', @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 @sas
EXEC @hr = sp_OADestroy @canonical
RETURN
END
-- Canonicalized table name must be lowercase. tn belongs in the token, not StringToSign.
DECLARE @start int
EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @start OUT
DECLARE @expiry int
EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @expiry OUT
EXEC sp_OAMethod @start, 'SetFromCurrentSystemTime', @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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @expiry, 'SetFromCurrentSystemTime', @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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @start, 'AddSeconds', @success OUT, -300
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @expiry, 'AddSeconds', @success OUT, 900
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'tn', 'tn', 'examplecustomers'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'sp', 'sp', 'r'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @start, 'GetAsTimestamp', @sTmp0 OUT, 0
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'st', 'st', @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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @expiry, 'GetAsTimestamp', @sTmp0 OUT, 0
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'se', 'se', @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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'spr', 'spr', 'https'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'sv', 'sv', '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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'spk', 'spk', '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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'epk', 'epk', '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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'srk', 'srk', '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 @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
EXEC sp_OAMethod @sas, 'SetTokenParam', @success OUT, 'erk', 'erk', 'customer-099'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
DECLARE @sasToken nvarchar(4000)
EXEC sp_OAMethod @sas, 'GenerateToken', @sasToken OUT
EXEC sp_OAGetProperty @sas, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
PRINT 'Could not sign the SAS.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
RETURN
END
DECLARE @files int
EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @files OUT
EXEC sp_OAMethod @files, 'WriteEntireTextFile', @success OUT, 'qa_data/azure/table-sas.txt', @sasToken, 'utf-8', 0
IF @success <> 1
BEGIN
PRINT 'Could not save private SAS token.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
EXEC @hr = sp_OADestroy @files
RETURN
END
PRINT 'Read-only Table SAS saved privately; expires in about 15 minutes.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @sas
EXEC @hr = sp_OADestroy @canonical
EXEC @hr = sp_OADestroy @start
EXEC @hr = sp_OADestroy @expiry
EXEC @hr = sp_OADestroy @files
END
GO