Function app not connecting to analysis services server getting Specified method is not supported
Muhammad Pathan
25
Reputation points
I am refreshing a data model in azure analysis services using a azure c# .net6 function app. i am getting Specified method is not supported when trying to connect to analysis services. my connection string looks correct. my server name is correct and initial catlog is name of the model. I was using the following blog as a guide and it looks like i am doing the connection string correct https://endjin.com/blog/2020/02/azure-analysis-services-how-to-open-a-connection-from-net
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.AnalysisServices.Tabular;
using Azure.Identity;
using System.Threading.Tasks;
namespace refreshModel
{
public static class AnalysisServicesRefreshFunction
{
[FunctionName("AnalysisServicesRefreshFunction")]
public static async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
// Retrieve environment variables
string env = Environment.GetEnvironmentVariable("ENV");
if (string.IsNullOrEmpty(env))
{
throw new InvalidOperationException("ENV environment variable is not found.");
}
// Analysis services details
string serverNamePrefix = "serverNamePrefix";
string serverName = serverNamePrefix + env;
string aasDatabaseName = "aasDatabaseName";
var credential = new DefaultAzureCredential();
var token = await credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { "https://uksouth.asazure.windows.net" }));
var connectionString = $"Provider=MSOLAP;Data Source=asazure://uksouth.asazure.windows.net/{serverName}:rw;Initial Catalog={aasDatabaseName};User ID=;Password={token.Token};Persist Security Info=True;Impersonation Level=Impersonate;";
using (var server = new Server())
{
try
{
server.Connect(connectionString);
}
catch (Exception ex)
{
log.LogError($"An error occurred while connecting to the server: {ex.Message}");
throw;
}
try
{
Database database = server.Databases.FindByName(aasDatabaseName);
if (database == null)
{
throw new InvalidOperationException("Azure analysis services database not found.");
}
Model model = database.Model;
if (model == null)
{
throw new InvalidOperationException("Model not found.");
}
// Refresh the model
model.RequestRefresh(RefreshType.Full);
model.SaveChanges();
log.LogInformation("Data model refresh requested successfully.");
}
catch (Exception ex)
{
log.LogError($"An error occurred while refreshing the data model: {ex.Message}");
throw;
}
}
}
}
}
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.AnalysisServices.NetCore.retail.amd64" Version="19.74.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
Sign in to answer