gpt4 book ai didi

azure - 使用 ADOMD.NET 连接到 Azure Analysis 时出现连接字符串错误

转载 作者:行者123 更新时间:2023-12-02 06:33:05 29 4
gpt4 key购买 nike

我正在尝试使用 ADOMD.NET 从云中部署的模型中检索 Azure Analysis Services 中的数据。代码片段如下,但我收到一个错误,指出 ConnectionString 无效。

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;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86d3f5e3f4c8e7ebe3bbfefffcc6e1ebe7efeaa8e5e9eb" rel="noreferrer noopener nofollow">[email protected]</a>;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)。从here下载。安装后,请确保您的 C# 项目在以下位置有对其的引用:

C:\Windows\Microsoft.NET\Assembly\GAC_MSIL\Microsoft.AnalysisServices.AdomdClient\v4.0_13.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.AdomdClient.dll

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

string connectionString = @"Data Source=asazure://westus.asazure.windows.net/bbacloud;User <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ed7daa3ebedfbecdefaf1f3fff7f0b0fdf1f3" rel="noreferrer noopener nofollow">[email protected]</a>;Password=pwdHere;Initial Catalog=DatabaseNameHere";

请注意一些事项。首先,它是用户 ID,而不是用户名。其次,用户需要是 Azure Active Directory 用户(组织帐户,而不是个人 LiveID)。最后,您需要指定初始目录,以确保在部署多个数据库时连接到正确的数据库。

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

关于azure - 使用 ADOMD.NET 连接到 Azure Analysis 时出现连接字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41739717/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com