gpt4 book ai didi

entity-framework - Azure 函数和 PowerShell : unable to set connection strings with Set-AzWebApp

转载 作者:行者123 更新时间:2023-12-02 22:57:45 28 4
gpt4 key购买 nike

出于部署目的,我创建了一个 PowerShell 脚本来设置应用设置。这通过

工作正常
$currentAppSettings = $app.SiteConfig.AppSettings

$appSettings = @{}
# Add existing App Settings
ForEach ($currentAppSetting in $currentAppSettings) {
$appSettings[$currentAppSetting.Name] = $currentAppSetting.Value
}

# Add new App Settings
$appSettings["someKey"] = "someValue"

# Update App Settings
Set-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName -AppSettings $appSettings

因为我现在使用 Entity Framework ,所以我还需要设置连接字符串。首先,我认为这应该像应用程序设置一样工作,只需添加 ConnectionStrings 参数:

$currentConnectionStrings = $app.SiteConfig.ConnectionStrings

$connectionStrings = @{}

ForEach ($currentConnectionString in $currentConnectionStrings) {
$connectionStrings[$currentConnectionString.Name] = $currentConnectionString.ConnectionString
}

$connectionStrings["someKey"] = "someValue"

Set-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName -ConnectionStrings $connectionStrings

但这失败并出现错误

Set-AzWebApp : Cannot validate argument on parameter 'ConnectionStrings'. Connection string type value pair must be of type 'System.Collections.Hashtable'

尽管 $connectionStrings 的类型是 System.Collections.Hashtable

还尝试使用自定义对象、数组等失败。

如何正确传递连接字符串?以及如何指定类型(例如 SQLAZURE)?

谢谢

最佳答案

根据 Set-AzwebApp 的文档,ConnectionStrings 应该是 Hastable

Set-AzWebApp
[[-AppServicePlan] <String>]
[[-DefaultDocuments] <String[]>]
[[-NetFrameworkVersion] <String>]
[[-PhpVersion] <String>]
[[-RequestTracingEnabled] <Boolean>]
[[-HttpLoggingEnabled] <Boolean>]
[[-DetailedErrorLoggingEnabled] <Boolean>]
[[-AppSettings] <Hashtable>]
[[-ConnectionStrings] <Hashtable>]
[[-HandlerMappings] <System.Collections.Generic.IList`1[Microsoft.Azure.Management.WebSites.Models.HandlerMapping]>]
[[-ManagedPipelineMode] <String>]
[[-WebSocketsEnabled] <Boolean>]
[[-Use32BitWorkerProcess] <Boolean>]
[[-AutoSwapSlotName] <String>]
[-ContainerImageName <String>]
[-ContainerRegistryUrl <String>]
[-ContainerRegistryUser <String>]
[-ContainerRegistryPassword <SecureString>]
[-EnableContainerContinuousDeployment <Boolean>]
[-HostNames <String[]>]
[-NumberOfWorkers <Int32>]
[-AsJob]
[-AssignIdentity <Boolean>]
[-HttpsOnly <Boolean>]
[-AzureStoragePath <WebAppAzureStoragePath[]>]
[-ResourceGroupName] <String>
[-Name] <String>
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]

您应该使用 Hashtable 设置 connectionstring,如下所示:

$connectionStrings = @{connectionStrings = @{Name="<ConnectionStringName>";Value="<ConnectionSyring>";type="<SQLAzure/SQLServer/Custom/MySql>"}}

Set-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName -ConnectionStrings $connectionStrings

关于entity-framework - Azure 函数和 PowerShell : unable to set connection strings with Set-AzWebApp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55487426/

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