gpt4 book ai didi

SQL Server 的 Azure ARM 模板不打印连接字符串

转载 作者:行者123 更新时间:2023-12-02 23:17:53 25 4
gpt4 key购买 nike

我有一个功能性 ARM 模板,用于部署带有依赖 SQL 数据库的简单 SQL Server。我正在尝试输出连接字符串,但收到以下错误:

{
"code":"DeploymentOutputEvaluationFailed",
"message":"Unable to evaluate template outputs: 'DatabaseConnectionString'. Please see error details and deployment operations. Please see https://aka.ms/arm-debug for usage details.",
"details":[
{
"code":"DeploymentOutputEvaluationFailed",
"target":"DatabaseConnectionString",
"message":"The template output 'DatabaseConnectionString' is not valid: The language expression property 'administratorLoginPassword' doesn't exist, available properties are 'administratorLogin, version, state, fullyQualifiedDomainName'.."
}
]
}

有人可以看看我做错了什么吗?我能够创建资源,但没有连接字符串的输出,这就是我收到的错误。

  1. 我已检查以确保我的参数名称正确。
  2. 我已使用 Visual Studio 验证了我的模板,它表明它是有效的。

azuredeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sqlserverName": {
"type": "string",
"minLength": 1,
"defaultValue": "[concat('sqlserver', uniqueString(resourceGroup().id))]"
},
"sqlserverAdminLogin": {
"type": "string",
"minLength": 1
},

"sqlserverAdminLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL Server."
}
},

"dbName": {
"type": "string",
"minLength": 1
},
"dbCollation": {
"type": "string",
"minLength": 1,
"defaultValue": "SQL_Latin1_General_CP1_CI_AS"
},
"dbEdition": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"dbRequestedServiceObjectiveName": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"S0",
"S1",
"S2",
"P1",
"P2",
"P3"
],
"metadata": {
"description": "Describes the performance level for Edition"
}
}
},
"variables": {
"sqlserverName": "[parameters('sqlserverName')]",
"databaseName": "[parameters('dbName')]"

},
"resources": [
{
"name": "[variables('sqlserverName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [ ],
"tags": {
"displayName": "sqlserver"
},
"properties": {
"administratorLogin": "[parameters('sqlserverAdminLogin')]",
"administratorLoginPassword": "[parameters('sqlserverAdminLoginPassword')]"
},
"resources": [
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"name": "[parameters('dbName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"tags": {
"displayName": "db"
},
"properties": {
"collation": "[parameters('dbCollation')]",
"edition": "[parameters('dbEdition')]",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "[parameters('dbRequestedServiceObjectiveName')]"
}
}
]
}],
"outputs": {
"sqlServerName": {
"type": "string",
"value": "[reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName]"
},
"databaseName": {
"type": "string",
"value": "[variables('databaseName')]"
},

"DatabaseConnectionString": {
"type": "string",
"value": "[concat('Server=tcp:',reference(variables('sqlserverName')).fullyQualifiedDomainName,',1433;Initial Catalog=',parameters('dbName'),';Persist Security Info=False;User ID=',reference(parameters('sqlserverName')).administratorLogin,';Password=',reference(parameters('sqlserverName')).administratorLoginPassword,';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
}

}
}

azuredeploy.parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {

/*Parameters for SQL Server */
"sqlserverName": {
"value": "talhasqlserver",
"metadata": {
"description": "This is your SQL Server name"
}
},

"sqlserverAdminLogin": {
"value": "talha",
"metadata": {
"description": "This is your SQL Server Login"
}
},

"sqlserverAdminLoginPassword": {
"value": "bleh",
"metadata": {
"description": "This is your SQL Server password. For privacy concerns, consider using KeyVault reference here."
}
},

/*Parameters for SQL Database */

"dbName": {
"value": "talhadbname",
"metadata": {
"description": "This is your SQL DB name."
}
},

"dbCollation": {
"value": "SQL_Latin1_General_CP1_CI_AS"
},

"dbEdition": {
"value": "Basic"
},

"dbRequestedServiceObjectiveName": {
"value": "Basic",
"metadata": {
"description": "Describes the performance level for Edition"
}
}
}
}

最佳答案

根据我的测试,“reference(parameters('sqlserverName'))”没有属性“administratorLoginPassword”,它只有属性“administratorLogin 版本状态 fullQualifiedDomainName”。如果您需要密码,请使用“parameters('sqlserverAdminLoginPassword')”。我的测试如下azuredeploy.json:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sqlserverName": {
"type": "string",
"minLength": 1,
"defaultValue": "[concat('sqlserver', uniqueString(resourceGroup().id))]"
},
"sqlserverAdminLogin": {
"type": "string",
"minLength": 1,
"defaultValue":"jimtest"
},

"sqlserverAdminLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL Server."
},
"defaultValue":"Password0123!"
},

"dbName": {
"type": "string",
"minLength": 1,
"defaultValue": "[concat('db', uniqueString(resourceGroup().id))]"
},
"dbCollation": {
"type": "string",
"minLength": 1,
"defaultValue": "SQL_Latin1_General_CP1_CI_AS"
},
"dbEdition": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"dbRequestedServiceObjectiveName": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"S0",
"S1",
"S2",
"P1",
"P2",
"P3"
],
"metadata": {
"description": "Describes the performance level for Edition"
}
}
},
"variables": {
"sqlserverName": "[parameters('sqlserverName')]",
"databaseName": "[parameters('dbName')]"

},
"resources": [
{
"name": "[variables('sqlserverName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [ ],
"tags": {
"displayName": "sqlserver"
},
"properties": {
"administratorLogin": "[parameters('sqlserverAdminLogin')]",
"administratorLoginPassword": "[parameters('sqlserverAdminLoginPassword')]"
},
"resources": [
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"name": "[parameters('dbName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"tags": {
"displayName": "db"
},
"properties": {
"collation": "[parameters('dbCollation')]",
"edition": "[parameters('dbEdition')]",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "[parameters('dbRequestedServiceObjectiveName')]"
}
}
]
}],
"outputs": {
"ServerObject": {
"type": "Object",
"value": "[reference(variables('sqlServerName'))]"
},
"Passwording":{
"type":"string",
"value":"[parameters('sqlserverAdminLoginPassword')]"

}
}


}

enter image description here

关于SQL Server 的 Azure ARM 模板不打印连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57486279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com