0

将结构化 ODBC 数据源添加到我的模型会导致错误。

我想使用 Microsoft.AnalysisServices.Tabular 库使用结构化(即 M / Power Query)、非旧版(即 ProviderDataSource)数据源在兼容级别 1400 的 SQL Analysis Services 服务器上生成表格模型。我使用 NuGet 包 Microsoft.AnalysisServices.retail.amd64 (16.3.0) 安装了该库。

这是我的数据源定义。

                myDatabase.Model.DataSources.Add(new StructuredDataSource()
                {
                    Name = "ODBC",
                    Description = "An structured ODBC data source definition",
                    ConnectionDetails = new ConnectionDetails()
                    {
                        Protocol = DataSourceProtocol.Odbc
                    },
                    Credential = new Credential()
                    {
                        AuthenticationKind = AuthenticationKind.UsernamePassword,
                        EncryptConnection = false,
                        Username = "MYUSERNAME",
                        Password = "MYPASSWORD"
                    }
                }

当我运行此代码时,我得到:

COM error: Microsoft.Data.Mashup; The given data source reference is not a valid data source.

它没有给我任何指示在哪里查看或具体有什么问题。我怀疑定义需要一个服务器地址,但是无法根据文档设置 ConnectionDetails 对象的地址属性。

ConnectionDetails.Address Property

Address of this connection. It can't be set, instead it should be modified directly.
4

1 回答 1

2

在查看我的问题并进一步调查文档时,我构建了这个解决方案。对于那些遇到同样问题的人,我想把它贴在这里会很好。

Credential credential = new Credential()
{
    AuthenticationKind = AuthenticationKind.UsernamePassword,
    EncryptConnection = false,
    Username = "MYUSERNAME",
    Password = "MYPASSWORD" // Please note that this won't persist.
};

ConnectionDetails connectionDetails = new ConnectionDetails("{ 'protocol': 'odbc', 'address': { 'options': { 'dsn': 'MYODBCDSN' } }, 'authentication': null, 'query': null }");

dbWithDataSource.Model.DataSources.Add(new StructuredDataSource()
{
    Name = "ODBC",
    Description = "An ODBC structured (ie. non-legacy) data source definition",
    ConnectionDetails = connectionDetails,
    Credential = credential,
    Options = new DataSourceOptions( "{ 'hierarchicalNavigation': true }" )
}

我基本上所做的是在 ConnectionDetails 构造函数中传入一个 JSON 字符串,同时设置“只读”地址属性。

于 2019-06-23T09:05:48.220 回答