在运行时版本 3.1 中连接到 Azure Functions 中的 Azure Analysis Services

Connect to Azure Analysis Services in Azure Function in Runtime version 3.1

我试图构建一个可以刷新表格分析服务器表的函数应用程序。我编写的代码参考了几个在线文档。当我尝试执行代码时,我在“var connStr = ConfigurationManager.ConnectionStrings["cubeConnection"].ConnectionString;"

在 Whosebug 中,我发现了一个类似的问题 (),其中要求创建一个 v1 函数。但就我而言,我只能使用 3.1。谁能帮我解决这个问题?

下面是我开发的脚本

#r "Microsoft.AnalysisServices.DLL"
#r "Microsoft.AnalysisServices.Tabular.DLL"
#r "Microsoft.AnalysisServices.Core.DLL"
#r "System.Configuration"

using System;
using System.Configuration;
using Microsoft.AnalysisServices.Tabular;


 public static void Run(TimerInfo myTimer, TraceWriter log) {
 Database db;
Model m;
try{
log.Info("started");
Microsoft.AnalysisServices.Tabular.Server asSrv = new Microsoft.AnalysisServices.Tabular.Server();
var connStr = ConfigurationManager.ConnectionStrings["cubeConnection"].ConnectionString; //failed here
log.Info("try started1");
asSrv.Connect(connStr);
log.Info("connection succeeded");
db = asSrv.Databases["DB_name"];
m = db.Model;
m.Tables["Table_name"].RequestRefresh(RefreshType.Full);
m.SaveChanges();     
asSrv.Disconnect();
}
catch (Exception e) {
log.Info($"{DateTime.Now} - {intname} - Processing function exception: {e.ToString()}");
throw;
}

}

正确答案是Azure Function V3不再使用ConfigurationManager

现在您可以使用以下代码获取连接字符串:

var connStr = Environment.GetEnvironmentVariable("cubeConnection");

需要在Settings-->Configuration-->Application settings中设置: