Reputation: 117
I've built base on several sample code, a C# script allowing to refresh a database hosted on a SSAS server but I receive an error code. Any idea how to fix the error?
C# Timer trigger function exception: System.NullReferenceException: Object reference not set to an instance of an object. at Submission#0.Run(TimerInfo myTimer, TraceWriter log) in D:\home\site\wwwroot\TimerTrigger1\run.csx:line 14
#r "Microsoft.AnalysisServices.Tabular.DLL"
#r "Microsoft.AnalysisServices.Core.DLL"
#r "System.Configuration"
using System;
using System.Configuration;
using Microsoft.AnalysisServices.Tabular;
using Microsoft.AnalysisServices.Core;
public static void Run(TimerInfo myTimer,TraceWriter log) {
try
{
Microsoft.AnalysisServices.Tabular.Server server = new Microsoft.AnalysisServices.Tabular.Server();
var connStr = ConfigurationManager.ConnectionStrings["ConnectStringBIDEV01"].ConnectionString;
server.Connect(connStr);
server.Disconnect();
}
catch (Exception e)
{
log.Info($"C# Timer trigger function exception: {e.ToString()}");
}
log.Info($"C# Timer trigger function finished at: {DateTime.Now}");
}
Upvotes: 3
Views: 2100
Reputation: 17790
The two problems Could not load type
and ConfigurationManager.ConnectionStrings get null
both result from the difference of Function Runtime.
v1 functions target at Full .NET Framework and v2 is running on .NET Core env. You may have created a v2 function(by default), where Analysis Services SDK(depends on .NET Framework) is not working and ConfigurationManager is not supported.
So the solution is simple, delete existing functions and change Function runtime version to ~1(In portal, Platform features> Function app settings>) and create a v1 function.
After that, we may see some warnings about Unable to find assembly
, just ignore them as we can connect to AnalysisServices successfully. If you meet error On-Premise Gateway is required to access the data source. Please install a unified gateway for the server
, please follow this tutorial to install.
Upvotes: 1
Reputation: 117
You've right, seems the connection string is null. So I've update it by adding an Initial catalog (my connection string does not contain this variable).
So to bypass that, I've replace my
var connStr = ConfigurationManager.ConnectionStrings["ConnectStringBIDEV01"].ConnectionString;
by
var connStr = "Provider=MSOLAP;Data Source=asazure://northeurope.asazure.windows.net/xxxxxxxx;Initial Catalog=xxxxxxx;User ID=xxxxxx;Password=xxxxxx";
Now I receive the following message ... I suspect it's a progress but how to fix that ?
C# Timer trigger function exception: System.TypeLoadException: Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at Microsoft.AnalysisServices.IdentityResolver.Dispose()
at Microsoft.AnalysisServices.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
at Microsoft.AnalysisServices.Core.Server.Connect(String connectionString, String sessionId, ObjectExpansion expansionType)
at Submission#0.Run(TimerInfo myTimer, TraceWriter log) in D:\home\site\wwwroot\TimerTrigger1\run.csx:line 16
Upvotes: 0