SSAS TOM-如何访问PowerBi模型的数据源
我正在使用 TOM 来询问和操作在 Power BI 中打开的 PBIX 文件。 PBIX 文件使用参数将连接字符串设置为为模型提供数据源的 SQL 数据库。我无法弄清楚如何从文件的元数据返回数据源。这是我的代码:
//this all works fine
Server server = new Server(); //from Microsoft.AnalysisServices.Tabular library
server.connect(connStr); //defined elsewhere
Model model = server.Databases[0].Model; //I am using this model to loop through tables and columns and it works fine
//these do not
model.DataSources
model.DataSources[0]
model.DataSources.find...
model.datasources.tostring() returns Microsoft.AnalysisServices.Tabular.DataSourcesCollection
看起来我有一个集合,但尝试使用 DataSources[0] 引用集合中的项目会引发参数越界错误,这在 DataSources.count 属性返回时是有意义的0(这似乎是错误的->)。在通过 PowerBI 桌面查看模型中的数据源时,我想要的数据源就在那里,完全由参数填充的数据库名称组成。
谁能告诉我这里发生了什么或者我如何从模型中获取数据源?
I'm using TOM to interrogate and manipulate a PBIX file open in Power BI. The PBIX file uses a parameter to set the connection string to the sql database that sources the data for the model. I cannot figure out how to return the datasource from the metadata for the file. Here is the code I have:
//this all works fine
Server server = new Server(); //from Microsoft.AnalysisServices.Tabular library
server.connect(connStr); //defined elsewhere
Model model = server.Databases[0].Model; //I am using this model to loop through tables and columns and it works fine
//these do not
model.DataSources
model.DataSources[0]
model.DataSources.find...
model.datasources.tostring() returns Microsoft.AnalysisServices.Tabular.DataSourcesCollection
So it seems I have a collection, but trying to reference an item in the collection using DataSources[0] throws a parameter out of bounds error, which sort of makes sense in that the DataSources.count property returns 0 (which seems wrong ->). In looking at the datasources in the model via PowerBI desktop, the one I want is in there, fully formed with the database name filled from the parameter.
Can anyone give me a clue as to what's going on here or how I can get the datasource from the model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据源用于适当的SSA中,但不是来自Power BI桌面模型。
Power BI模型只会在 QueryDefinition 列中具有M代码的表达式和分区。 表达式是未加载到表的功率查询,分区是直接加载到表的功率查询。您应该在这两个地方之一中找到连接信息。与具有列中有连接信息的数据源不同,您必须自己从查询中解析连接信息。
您可以通过安装表格编辑器V2工具并从Power BI中的外部工具菜单启动它来轻松查看所有这些内容。请参阅此页面有关其脚本可容纳的详细信息。
启动表格编辑器

tagular编辑器的对象树

DataSources are used in SSAS proper, but not from Power BI Desktop models.
A Power BI model will only have Expressions and Partitions with M code in the QueryDefinition column. Expressions are Power Queries that aren't loaded to a table, and Partitions are Power Queries that are loaded directly to a table. You should find the connection info in one of these 2 places. You have to parse out connection info yourself from the query, unlike DataSources that have connection info in columns.
You can view all of this easily by installing the Tabular Editor v2 tool and launching it from the External Tools menu in Power BI. See this page for details on its scripting capabilities.
Launching Tabular Editor

Object tree from Tabular Editor

Shared Expression properties from Tabular Editor
