2013 C# connection to PowerPivot DataModel

强颜欢笑 提交于 2019-12-11 16:25:11

问题


This article Connecting to PowerPivot with C# is the closest to my question but it seems that it is out of date. I attempted the methods they showed in the answer but the example

 ThisWorkbook.Connections["PowerPivot Data"].OLEDBConnection.ADOConnection

Does not return the connection information, rather an exception.

But I was able to access the PP Data Model using:

ThisAddIn.Current.Application.ActiveWorkbook.Connections[1]. ModelTables[1].ModelTableColumns[1].Name`

But the object only allows you to look at the column names in the model. I wasn't able to get the connection information or anything.

ThisAddIn.Current.Application.ActiveWorkbook.Connections[1].ModelConnection.ADOConnection`

causes an exception and so does:

ThisAddIn.Current.Application.ActiveWorkbook.Connections[1].OLEDBConnection.ADOConnection

MY QUESTIONS

  • Have I made a mistake in my code?
  • Is there another method to connect to the datamodel that I haven't listed above?
  • Is it possible to read the records in the datamodel? (I was able to read column names)

Thank you for your time!


回答1:


string ConnString = "Provider=MSOLAP;Data Source=$Embedded$; Locale Identifier=1033;Location=" + ThisAddIn.Current.Application.ActiveWorkbook.FullName + ";SQLQueryMode=DataKeys";

Microsoft.AnalysisServices.Server OlapServer = new Microsoft.AnalysisServices.Server();

OlapServer.Connect(ConnString);



来源:https://stackoverflow.com/questions/24643366/2013-c-sharp-connection-to-powerpivot-datamodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!