如何使用链接服务从.NET .dll文件连接到Azure

时间:2018-02-05 02:57:12

标签: c# .net azure azure-analysis-services

我想编写一个代码,类似于Visual Studio中此链接(https://azure.microsoft.com/en-us/blog/automating-azure-analysis-services-processing-with-azure-functions/)底部的代码并构建DLL文件。但是,我想使用Azure门户中的现有链接服务而不是使用连接字符串。

目标是创建一个刷新我的多维数据集的DLL,同时使用已存在于我的Azure门户中的现有链接服务。

这可能吗?

感谢。

#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)

{

    log.Info($"C# Timer trigger function started at: {DateTime.Now}");  

    try

            {

                Microsoft.AnalysisServices.Tabular.Server asSrv = new Microsoft.AnalysisServices.Tabular.Server();

                var connStr = ConfigurationManager.ConnectionStrings["AzureASConnString"].ConnectionString; // Change this to a Linked Service connection

                asSrv.Connect(connStr);

                Database db = asSrv.Databases["AWInternetSales2"];

                Model m = db.Model;

                db.Model.RequestRefresh(RefreshType.Full);     // Mark the model for refresh

                //m.RequestRefresh(RefreshType.Full);     // Mark the model for refresh

                m.Tables["Date"].RequestRefresh(RefreshType.Full);     // Mark only one table for refresh

                db.Model.SaveChanges();     //commit  which will execute the refresh

                asSrv.Disconnect();

            }

            catch (Exception e)

            {

                log.Info($"C# Timer trigger function exception: {e.ToString()}");

            }

    log.Info($"C# Timer trigger function finished at: {DateTime.Now}"); 

}    

1 个答案:

答案 0 :(得分:0)

所以我猜你正在使用数据工厂,并且想要从管道中处理分析服务模型。我没有看到你的问题与Data湖商店有什么关系。

要从数据工厂触发Azure功能(仅限v2),您必须使用Web活动。可以将链接服务作为有效负载的一部分传递,如documentation所示。它看起来像这样:

{
"body": {
    "myMessage": "Sample",
    "linkedServices": [{
        "name": "MyService1",
        "properties": {
            ...
        }
    }]
}

但是,数据工厂中没有Analysis服务链接服务,至少,我没有听说过这样的事情。然而,传递来自管道的连接字符串似乎是一个好主意。您可以将其作为pipeline parameter传递到您的网络请求主体中。

在管道中创建参数 enter image description here

将其添加到您的Web活动有效负载

{
    "body": {
            "AzureASConnString": "@pipeline().parameters.AzureASConnString"
}

您可以从描述为here

的函数中检索此值
相关问题