Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute query on SQL Server Analysis Services with IronPython

I was able to connect to SQL server Analysis service in Python using Microsoft.AnalysisServices.dll, and now I can't execute query on cube.

I've tried Execute method same as following:

amoServer.Execute('select from finance')

After issuing Execute method I have this error:

<Microsoft.AnalysisServices.XmlaError object at 0x000000000000002B [Microsoft.AnalysisServices.XmlaError]>

Note: I'm using IronPython with Python 2.7 on Windows Server 64Bit.

What's the problem?

like image 680
Aida.Mirabadi Avatar asked Feb 12 '23 12:02

Aida.Mirabadi


1 Answers

its better use Microsoft.AnalysisServices.AdomdClient.dll and mdx query. and set query result in Datasets in Ststem.Data assembly something like this:

clr.AddReference ("Microsoft.AnalysisServices.AdomdClient.dll")
clr.AddReference ("System.Data")

from Microsoft.AnalysisServices.AdomdClient import AdomdConnection , AdomdDataAdapter
from System.Data import DataSet

conn = AdomdConnection("Data Source=0.0.0.0;Catalog=MyCatalog;")
conn.Open()
cmd = conn.CreateCommand()
cmd.CommandText = "your mdx query" # in your case 'select from finance'
adp = AdomdDataAdapter(cmd)
datasetParam =  DataSet()
adp.Fill(datasetParam)
conn.Close();

# datasetParam hold your result as collection a\of tables
# each tables has rows
# and each row has columns
print datasetParam.Tables[0].Rows[0][0]
like image 127
Behrooz Avatar answered Feb 15 '23 09:02

Behrooz