使用 ADOMD.NET 连接到 Azure Analysis 时出现连接字符串错误 [英] Connection String error while using ADOMD.NET to connect to Azure Analysis

查看:26
本文介绍了使用 ADOMD.NET 连接到 Azure Analysis 时出现连接字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ADOMD.NET 从云中部署的模型中检索 Azure 分析服务中的数据.代码片段如下,但我收到一个错误,提示 ConnectionString 无效.

I am trying to retrieve data from Azure Analysis Services using ADOMD.NET from a deployed model in cloud. The code snippet is as below, but i am getting an error that the ConnectionString in invalid.

using Microsoft.AnalysisServices.AdomdClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test_Analysis_Service_retrieval
{
    class Program
    {
        static void Main(string[] args)
        {
            string queryString = @"SELECT [MAP_CUST_NAME] FROM [AAS_MAPLOOKUP] where [MAP_ACT_NO] = '120000810';";
            string connectionString = @"Data Source=asazure://westus.asazure.windows.net/bbacloud;UserName=xyz@gmail.com;Password=ABC@123;";

            using (AdomdConnection connection = new AdomdConnection(connectionString))
            {
                CellSet AASOutput = null;
                System.Xml.XmlReader reader = null;
                try
                {
                    string s = connection.ConnectionString;
                    Console.WriteLine(s);
                    connection.Open();
                    AdomdCommand command = new AdomdCommand(queryString, connection);
                    command.CommandTimeout = 100000;
                    reader = command.ExecuteXmlReader();
                    Console.WriteLine(reader.ReadOuterXml());
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                    connection.Close();
                }
            }
        }
    }
}

推荐答案

您需要做的第一件事是确保安装了最新的 ADOMD.NET (AdomdClient).从此处下载.安装后,请确保您的 C# 项目在以下位置引用了它:

The first thing you need to do is to ensure you have the latest ADOMD.NET (AdomdClient) installed. Download it from here. After you have installed it, then make sure your C# project has a reference to it at:

C:WindowsMicrosoft.NETassemblyGAC_MSILMicrosoft.AnalysisServices.AdomdClientv4.0_13.0.0.0__89845dcd8080cc91Microsoft.AnalysisServices.AdomdClient.dll

接下来,您需要将连接字符串更改为:

Next, you need to change your connection string to:

string connectionString = @"Data Source=asazure://westus.asazure.windows.net/bbacloud;User ID=user@domain.com;Password=pwdHere;Initial Catalog=DatabaseNameHere";

注意几点.首先,它是用户 ID 而不是用户名.其次,用户需要是 Azure Active Directory 用户(组织帐户,而不是个人 LiveID).最后,您需要指定初始目录以确保您连接到正确的数据库,以防您部署了多个数据库.

Note a few things. First, it's User ID not UserName. Second, the user needs to be an Azure Active Directory user (an organizational account, not a personal LiveID). Finally, you need to specify the Initial Catalog to ensure that you connect to the correct database in case you ever have multiple databases deployed.

更新:Nuget 上提供了最新的 此处.或者,如果您正在构建 .NET Core 应用程序,请使用 this.

Update: The latest is available on Nuget for here. Or if you are building a .NET Core app use this.

这篇关于使用 ADOMD.NET 连接到 Azure Analysis 时出现连接字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆