Ready to get started?

Download a free trial of the SQL Analysis Services ODBC Driver to get started:

 Download Now

Learn more:

SQL Server Analysis Services Icon SQL Analysis Services ODBC Driver

The SQL Analysis Services ODBC Driver is a powerful tool that allows you to connect with live data from SQL Analysis Services, directly from any applications that support ODBC connectivity.

Access Analysis Services report data like you would a database, through a standard ODBC Driver interface. Supports Direct Query and MDX query capabilities.

Using the CData ODBC Driver for SQL Analysis Services in PyCharm



Connect to SQL Analysis Services as an ODBC data source in PyCharm using the CData ODBC Driver for SQL Analysis Services.

The CData ODBC Drivers can be used in any environment that supports loading an ODBC Driver. In this tutorial we will explore using the CData ODBC Driver for SQL Analysis Services from within PyCharm. Included are steps for adding the CData ODBC Driver as a data source, as well as basic PyCharm code to query the data source and display results.

To begin, this tutorial will assume that you have already installed the CData ODBC Driver for SQL Analysis Services as well as PyCharm.

Add Pyodbc to the Project

Follow the steps below to add the pyodbc module to your project.

  1. Click File -> Settings to open the project settings window.
  2. Click Project Interpreter from the Project: YourProjectName menu.
  3. To add pyodbc, click the + button and enter pyodbc.
  4. Click Install Package to install pyodbc.

Connect to SQL Analysis Services

You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.

To connect, provide authentication and set the Url property to a valid SQL Server Analysis Services endpoint. You can connect to SQL Server Analysis Services instances hosted over HTTP with XMLA access. See the Microsoft documentation to configure HTTP access to SQL Server Analysis Services.

To secure connections and authenticate, set the corresponding connection properties, below. The data provider supports the major authentication schemes, including HTTP and Windows, as well as SSL/TLS.

  • HTTP Authentication

    Set AuthScheme to "Basic" or "Digest" and set User and Password. Specify other authentication values in CustomHeaders.

  • Windows (NTLM)

    Set the Windows User and Password and set AuthScheme to "NTLM".

  • Kerberos and Kerberos Delegation

    To authenticate with Kerberos, set AuthScheme to NEGOTIATE. To use Kerberos delegation, set AuthScheme to KERBEROSDELEGATION. If needed, provide the User, Password, and KerberosSPN. By default, the data provider attempts to communicate with the SPN at the specified Url.

  • SSL/TLS:

    By default, the data provider attempts to negotiate SSL/TLS by checking the server's certificate against the system's trusted certificate store. To specify another certificate, see the SSLServerCert property for the available formats.

You can then access any cube as a relational table: When you connect the data provider retrieves SSAS metadata and dynamically updates the table schemas. Instead of retrieving metadata every connection, you can set the CacheLocation property to automatically cache to a simple file-based store.

See the Getting Started section of the CData documentation, under Retrieving Analysis Services Data, to execute SQL-92 queries to the cubes.

Below is the syntax for a DSN:

[CData SSAS Source] Driver = CData ODBC Driver for SQL Analysis Services Description = My Description User = myuseraccount Password = mypassword URL = http://localhost/OLAP/msmdpump.dll

Execute SQL to SQL Analysis Services

Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.

import pyodbc cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for SSAS};User = myuseraccount;Password = mypassword;URL = http://localhost/OLAP/msmdpump.dll;') cursor = cnxn.cursor() cursor.execute("SELECT Fiscal_Year, Sales_Amount FROM Adventure_Works WHERE Fiscal_Year = 'FY 2008'") rows = cursor.fetchall() for row in rows: print(row.Fiscal_Year, row.Sales_Amount)

After connecting to SQL Analysis Services in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to SQL Analysis Services data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.