解决存储帐户名称错误Resolve errors for storage account names

本文介绍了部署存储帐户时可能遇到的命名错误。This article describes naming errors you may encounter when deploying a storage account.

症状Symptom

如果存储帐户名称包含禁用的字符,则会收到如下错误:If your storage account name includes prohibited characters, you receive an error like:

Code=AccountNameInvalid
Message=S!torageckrexph7isnoc is not a valid storage account name. Storage account name must be 
between 3 and 24 characters in length and use numbers and lower-case letters only.

对于存储帐户,必须为此资源提供一个在 Azure 中唯一的名称。For storage accounts, you must provide a name for the resource that is unique across Azure. 如果不提供唯一名称,则会收到如下所示的错误:If you do not provide a unique name, you receive an error like:

Code=StorageAccountAlreadyTaken
Message=The storage account named mystorage is already taken.

如果部署的存储帐户与订阅中的现有存储帐户名称相同,但提供一个不同的位置,则会收到一个错误消息,指示该存储帐户已存在于其他位置。If you deploy a storage account with the same name as an existing storage account in your subscription, but provide a different location, you receive an error indicating the storage account already exists in a different location. 请删除现有存储帐户,或提供与现有存储帐户相同的位置。Either delete the existing storage account, or provide the same location as the existing storage account.

原因Cause

存储帐户名称长度必须为 3 到 24 个字符,并且只能使用数字和小写字母。Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. 该名称必须是唯一的。The name must be unique.

解决方案Solution

请确保存储帐户名称是唯一的。Make sure the storage account name is unique. 可将命名约定与 uniqueString 函数的结果连接起来创建一个唯一名称。You can create a unique name by concatenating your naming convention with the result of the uniqueString function.

"name": "[concat('storage', uniqueString(resourceGroup().id))]",
"type": "Microsoft.Storage/storageAccounts",

请确保存储帐户名称不超过 24 个字符。Make sure your storage account name does not exceed 24 characters. uniqueString 函数返回 13 个字符。The uniqueString function returns 13 characters. 如果将前缀或后缀连接到 uniqueString 结果,请提供 11 个字符(或更少字符)的值。If you concatenate a prefix or postfix to the uniqueString result, provide a value that is 11 characters or less.

"parameters": {
  "storageNamePrefix": {
    "type": "string",
    "maxLength": 11,
    "defaultValue": "storage",
    "metadata": {
      "description": "The value to use for starting the storage account name."
    }
  }
}

请确保存储帐户名称不包含任何大写字母或特殊字符。Make sure your storage account name does not include any upper-case letters or special characters.