SQL Server
SQL Server
Azure Create Storage Account
See more Azure Storage Accounts Examples
Demonstrates how to create an Azure storage account.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
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token
DECLARE @jsonToken int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT
EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/azureToken.json'
-- Assuming success..
EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token'
EXEC sp_OASetProperty @http, 'AuthToken', @sTmp0
EXEC sp_OAGetProperty @http, 'AuthToken', @sTmp0 OUT
PRINT 'AuthToken: ' + @sTmp0
EXEC sp_OASetProperty @http, 'Accept', 'application/json'
-- Create the following JSON:
-- {
-- "sku": {
-- "name": "Standard_GRS"
-- },
-- "kind": "StorageV2",
-- "location": "eastus2",
-- }
-- Use this online tool to generate the code from sample JSON:
-- Generate Code to Create JSON
DECLARE @jsonRequestBody int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonRequestBody OUT
EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'sku.name', 'Standard_GRS'
EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'kind', 'StorageV2'
EXEC sp_OAMethod @jsonRequestBody, 'UpdateString', @success OUT, 'location', 'eastus2'
DECLARE @url nvarchar(4000)
SELECT @url = 'https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01'
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'PUT', @url, @jsonRequestBody, 'application/json', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @jsonRequestBody
EXEC @hr = sp_OADestroy @resp
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT 'Response Status Code: ' + @iTmp0
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0
EXEC sp_OASetProperty @json, 'EmitCompact', 0
EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
PRINT @sTmp0
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
IF @iTmp0 >= 300
BEGIN
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @jsonRequestBody
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @json
RETURN
END
-- Successful requests to create a new account return a 202 status code with an empty response body. The storage account is created asynchronously.
-- If the account already exists or is being provisioned, the request response has a 200 return code with the configuration of the existing storage account in the response body.
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
IF @iTmp0 = 202
BEGIN
EXEC sp_OAMethod @resp, 'GetHeaderField', @sTmp0 OUT, 'Azure-AsyncOperation'
PRINT 'Azure-AsyncOperation: ' + @sTmp0
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
IF @iTmp0 = 200
BEGIN
-- Parse a response like this:
-- {
-- "sku": {
-- "name": "Standard_GRS",
-- "tier": "Standard"
-- },
-- "kind": "StorageV2",
-- "id": "/subscriptions/6c42643b-ebef-45f0-b917-b3583b84a57f/resourceGroups/gChilkat/providers/Microsoft.Storage/storageAccounts/chilkatsoftware",
-- "name": "chilkatsoftware",
-- "type": "Microsoft.Storage/storageAccounts",
-- "location": "eastus2",
-- "tags": {},
-- "properties": {
-- "networkAcls": {
-- "bypass": "AzureServices",
-- "virtualNetworkRules": [
-- ],
-- "ipRules": [
-- ],
-- "defaultAction": "Allow"
-- },
-- "supportsHttpsTrafficOnly": false,
-- "encryption": {
-- "services": {
-- "file": {
-- "enabled": true,
-- "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
-- },
-- "blob": {
-- "enabled": true,
-- "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
-- }
-- },
-- "keySource": "Microsoft.Storage"
-- },
-- "accessTier": "Hot",
-- "provisioningState": "Succeeded",
--
-- "creationTime": "2019-05-14T22:18:33.1309165Z",
-- "primaryEndpoints": {
-- "dfs": "https://chilkatsoftware.dfs.core.windows.net/",
-- "web": "https://chilkatsoftware.z20.web.core.windows.net/",
-- "blob": "https://chilkatsoftware.blob.core.windows.net/",
-- "queue": "https://chilkatsoftware.queue.core.windows.net/",
-- "table": "https://chilkatsoftware.table.core.windows.net/",
-- "file": "https://chilkatsoftware.file.core.windows.net/"
-- },
-- "primaryLocation": "eastus2",
-- "statusOfPrimary": "available",
-- "secondaryLocation": "centralus",
-- "statusOfSecondary": "available"
-- }
-- }
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
DECLARE @skuName nvarchar(4000)
DECLARE @skuTier nvarchar(4000)
DECLARE @kind nvarchar(4000)
DECLARE @id nvarchar(4000)
DECLARE @name nvarchar(4000)
DECLARE @v_type nvarchar(4000)
DECLARE @location nvarchar(4000)
DECLARE @propertiesNetworkAclsBypass nvarchar(4000)
DECLARE @propertiesNetworkAclsDefaultAction nvarchar(4000)
DECLARE @propertiesSupportsHttpsTrafficOnly int
DECLARE @propertiesEncryptionServicesFileEnabled int
DECLARE @propertiesEncryptionServicesFileLastEnabledTime nvarchar(4000)
DECLARE @propertiesEncryptionServicesBlobEnabled int
DECLARE @propertiesEncryptionServicesBlobLastEnabledTime nvarchar(4000)
DECLARE @propertiesEncryptionKeySource nvarchar(4000)
DECLARE @propertiesAccessTier nvarchar(4000)
DECLARE @propertiesProvisioningState nvarchar(4000)
DECLARE @propertiesCreationTime nvarchar(4000)
DECLARE @propertiesPrimaryEndpointsDfs nvarchar(4000)
DECLARE @propertiesPrimaryEndpointsWeb nvarchar(4000)
DECLARE @propertiesPrimaryEndpointsBlob nvarchar(4000)
DECLARE @propertiesPrimaryEndpointsQueue nvarchar(4000)
DECLARE @propertiesPrimaryEndpointsTable nvarchar(4000)
DECLARE @propertiesPrimaryEndpointsFile nvarchar(4000)
DECLARE @propertiesPrimaryLocation nvarchar(4000)
DECLARE @propertiesStatusOfPrimary nvarchar(4000)
DECLARE @propertiesSecondaryLocation nvarchar(4000)
DECLARE @propertiesStatusOfSecondary nvarchar(4000)
DECLARE @i int
DECLARE @count_i int
EXEC sp_OAMethod @json, 'StringOf', @skuName OUT, 'sku.name'
EXEC sp_OAMethod @json, 'StringOf', @skuTier OUT, 'sku.tier'
EXEC sp_OAMethod @json, 'StringOf', @kind OUT, 'kind'
EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'id'
EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'name'
EXEC sp_OAMethod @json, 'StringOf', @v_type OUT, 'type'
EXEC sp_OAMethod @json, 'StringOf', @location OUT, 'location'
EXEC sp_OAMethod @json, 'StringOf', @propertiesNetworkAclsBypass OUT, 'properties.networkAcls.bypass'
EXEC sp_OAMethod @json, 'StringOf', @propertiesNetworkAclsDefaultAction OUT, 'properties.networkAcls.defaultAction'
EXEC sp_OAMethod @json, 'BoolOf', @propertiesSupportsHttpsTrafficOnly OUT, 'properties.supportsHttpsTrafficOnly'
EXEC sp_OAMethod @json, 'BoolOf', @propertiesEncryptionServicesFileEnabled OUT, 'properties.encryption.services.file.enabled'
EXEC sp_OAMethod @json, 'StringOf', @propertiesEncryptionServicesFileLastEnabledTime OUT, 'properties.encryption.services.file.lastEnabledTime'
EXEC sp_OAMethod @json, 'BoolOf', @propertiesEncryptionServicesBlobEnabled OUT, 'properties.encryption.services.blob.enabled'
EXEC sp_OAMethod @json, 'StringOf', @propertiesEncryptionServicesBlobLastEnabledTime OUT, 'properties.encryption.services.blob.lastEnabledTime'
EXEC sp_OAMethod @json, 'StringOf', @propertiesEncryptionKeySource OUT, 'properties.encryption.keySource'
EXEC sp_OAMethod @json, 'StringOf', @propertiesAccessTier OUT, 'properties.accessTier'
EXEC sp_OAMethod @json, 'StringOf', @propertiesProvisioningState OUT, 'properties.provisioningState'
EXEC sp_OAMethod @json, 'StringOf', @propertiesCreationTime OUT, 'properties.creationTime'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryEndpointsDfs OUT, 'properties.primaryEndpoints.dfs'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryEndpointsWeb OUT, 'properties.primaryEndpoints.web'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryEndpointsBlob OUT, 'properties.primaryEndpoints.blob'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryEndpointsQueue OUT, 'properties.primaryEndpoints.queue'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryEndpointsTable OUT, 'properties.primaryEndpoints.table'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryEndpointsFile OUT, 'properties.primaryEndpoints.file'
EXEC sp_OAMethod @json, 'StringOf', @propertiesPrimaryLocation OUT, 'properties.primaryLocation'
EXEC sp_OAMethod @json, 'StringOf', @propertiesStatusOfPrimary OUT, 'properties.statusOfPrimary'
EXEC sp_OAMethod @json, 'StringOf', @propertiesSecondaryLocation OUT, 'properties.secondaryLocation'
EXEC sp_OAMethod @json, 'StringOf', @propertiesStatusOfSecondary OUT, 'properties.statusOfSecondary'
END
PRINT 'Success.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonToken
EXEC @hr = sp_OADestroy @jsonRequestBody
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @json
END
GO