Function app not connecting to analysis services server getting Specified method is not supported

Muhammad Pathan 25 Reputation points
2024-02-08T15:37:05.84+00:00

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;
                }
            }
        }
    }
}

added error log enter image description here packages use

<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" />
Azure Analysis Services
Azure Analysis Services
An Azure service that provides an enterprise-grade analytics engine.
443 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,573 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,580 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,136 questions
{count} vote