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

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

问题描述

我正在尝试使用ADOMD.NET从云中的已部署模型中从Azure Analysis Services检索数据.代码段如下,但是我收到一个错误,提示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:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.AnalysisServices.AdomdClient\v4.0_13.0.0.0__89845dcd8080cc91\Microsoft.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,而不是UserName.其次,用户必须是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.

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

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