我很困扰。我想在 Azure v3 函数(.Net Core 3.1)中获取连接字符串。
我的本地设置看起来像
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true"
},
"ConnectionStrings": {
"DefaultConnection": "bla bla"
}
}
在我做的功能中string defaultConnection = Environment.GetEnvironmentVariable("ConnectionStrings:DefaultConnection");
这在本地工作正常,但在 Azure 上,defaultConnection 为空。我在函数的应用程序设置的连接字符串部分下定义了连接。我的方法对 Azure 函数 v3 是否正确?
最佳答案
您需要指定连接字符串前缀(请参阅 documentation ):
Environment.GetEnvironmentVariable("CUSTOMCONNSTR_DefaultConnection");
关于c# - 在 Azure Function v3 中获取连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62406026/