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

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.

Microsoft reference.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Config
long li_SameText1
long li_SameText2
oleobject loo_Sas
oleobject loo_Canonical
oleobject loo_Start
oleobject loo_Expiry
string ls_SasToken
oleobject loo_Files

li_Success = 0

//  StringBuilder compares text by value in every generated language.
loo_TextCompare = create oleobject
li_rc = loo_TextCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_TextCompare
    MessageBox("Error","Connecting to COM object failed")
    return
end if
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
loo_Config = create oleobject
li_rc = loo_Config.ConnectToNewObject("Chilkat.JsonObject")

loo_Config.Strict = 1
li_Success = loo_Config.LoadFile("qa_data/azure/storage.json")
if li_Success <> 1 then
    Write-Debug "Could not load private Azure configuration."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("account"))
li_SameText1 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("account") <> 1) OR (li_SameText1 = 1) then
    Write-Debug "Supply the storage account name."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

//  access_key is the base64 account key, not a connection string or SAS.
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("access_key"))
li_SameText2 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("access_key") <> 1) OR (li_SameText2 = 1) then
    Write-Debug "Supply the base64 account access key."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

loo_Sas = create oleobject
li_rc = loo_Sas.ConnectToNewObject("Chilkat.AuthAzureSAS")

loo_Sas.AccessKey = loo_Config.StringOf("access_key")
loo_Sas.StringToSign = "sp,st,se,resource,si,sip,spr,sv,spk,srk,epk,erk"
loo_Canonical = create oleobject
li_rc = loo_Canonical.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Canonical.Append("/table/")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    return
end if

li_Success = loo_Canonical.Append(loo_Config.StringOf("account"))
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    return
end if

li_Success = loo_Canonical.Append("/examplecustomers")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    return
end if

li_Success = loo_Sas.SetNonTokenParam("resource",loo_Canonical.GetAsString())
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    return
end if

//  Canonicalized table name must be lowercase. tn belongs in the token, not StringToSign.
loo_Start = create oleobject
li_rc = loo_Start.ConnectToNewObject("Chilkat.CkDateTime")

loo_Expiry = create oleobject
li_rc = loo_Expiry.ConnectToNewObject("Chilkat.CkDateTime")

li_Success = loo_Start.SetFromCurrentSystemTime()
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Expiry.SetFromCurrentSystemTime()
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Start.AddSeconds(-300)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Expiry.AddSeconds(900)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("tn","tn","examplecustomers")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("sp","sp","r")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("st","st",loo_Start.GetAsTimestamp(0))
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("se","se",loo_Expiry.GetAsTimestamp(0))
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("spr","spr","https")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("sv","sv","2026-04-06")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("spk","spk","customers-west")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("epk","epk","customers-west")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("srk","srk","customer-001")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

li_Success = loo_Sas.SetTokenParam("erk","erk","customer-099")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

ls_SasToken = loo_Sas.GenerateToken()
if loo_Sas.LastMethodSuccess <> 1 then
    Write-Debug "Could not sign the SAS."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    return
end if

loo_Files = create oleobject
li_rc = loo_Files.ConnectToNewObject("Chilkat.FileAccess")

li_Success = loo_Files.WriteEntireTextFile("qa_data/azure/table-sas.txt",ls_SasToken,"utf-8",0)
if li_Success <> 1 then
    Write-Debug "Could not save private SAS token."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Sas
    destroy loo_Canonical
    destroy loo_Start
    destroy loo_Expiry
    destroy loo_Files
    return
end if

Write-Debug "Read-only Table SAS saved privately; expires in about 15 minutes."


destroy loo_TextCompare
destroy loo_Config
destroy loo_Sas
destroy loo_Canonical
destroy loo_Start
destroy loo_Expiry
destroy loo_Files