C# 在运行时版本3.1的Azure函数中连接到Azure Analysis Services
我试图构建一个功能应用程序,可以刷新表格分析服务器表。我写的代码参考了一些在线可用的文档。当我试图执行代码时,我在“var connStr=ConfigurationManager.ConnectionStrings[“cubeConnection”].ConnectionString;处得到了“对象引用未设置为对象的实例”错误 在stackoverflow中,我发现了一个类似的问题(),要求它创建v1函数。但就我而言,我只能使用3.1。有人能帮我吗 下面是我开发的脚本C# 在运行时版本3.1的Azure函数中连接到Azure Analysis Services,c#,azure,azure-functions,c#-3.0,C#,Azure,Azure Functions,C# 3.0,我试图构建一个功能应用程序,可以刷新表格分析服务器表。我写的代码参考了一些在线可用的文档。当我试图执行代码时,我在“var connStr=ConfigurationManager.ConnectionStrings[“cubeConnection”].ConnectionString;处得到了“对象引用未设置为对象的实例”错误 在stackoverflow中,我发现了一个类似的问题(),要求它创建v1函数。但就我而言,我只能使用3.1。有人能帮我吗 下面是我开发的脚本 #r "Mic
#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");
您需要在设置-->配置-->应用程序设置中设置它:
您缺少配置文件,或者配置文件不包含“cubeConnection”我已在设置-->配置-->连接字符串中创建了“cubeConnection”,是否必须创建单独的配置文件?应为App.config:请参阅