Search code examples
odbcssasazure-cosmosdb

Can you connect to CosmosDB from SSAS (Tabular) using the ODBC driver for Cosmos?


I have followed the instructions for setting up a new ODBC connection to CosmosDB. I would like to use this ODBC connection in an SSAS tabular project but I don't see a way to do that. I am on SSDT 15.1. When I click the "Others" data source for OLEDB/ODBC in SSAS, it only gives me build options for OLEDB. It's not clear how I would use this to connect to my CosmosDB ODBC.

Has anyone figured out how to do this? According to Microsoft it is possible but they have no instructions for it.


Solution

  • It is possible. Launch the "ODBC Data Sources (32-bit)" app and setup a system DSN as described in this article. Then open "ODBC Data Sources (64-bit)" and setup a system DSN with the exact same name as the 32-bit DSN. The reason is that Visual Studio is 32-bit so when performing some steps it requires a 32-bit driver, but once SSAS loads the table into memory that occurs in a 64-bit process which requires the 64-bit driver. Setup these DSNs on your workstation and on the workspace server (local if using the integrated workspace or on a dev server if using a remote workspace).

    Using ODBC drivers inside Analysis Services Tabular doesn't seem to be very well documented. Basically you need to use the OLEDB for ODBC driver.

    When creating a new connection in Visual Studio in your SSAS model, instead of choosing the driver from the dropdown, just type in the following connection string:

    Provider=MSDASQL;DSN=YourDsnNameHere
    

    If you prefer inline connection strings that make deploying easier to do without ODBC DSNs then you can use this connection string:

    Provider=MSDASQL;DRIVER={Microsoft DocumentDB ODBC Driver};Host="https://yourcosmosdbname.documents.azure.com:443/";AuthenticationKey="authKeyHere!";LocalSchemaFile="c:\folder\yourCosmosSchema.json";KeyEncrypted=true;NumberOfRetries=5;DSNType=0;Consistency=1
    

    Regardless of which connection string you will probably have to write a query such as select * from CollectionName rather than picking from the table list.

    If you are using 1400 compatibility level models (Analysis Services 2017 or Azure Analysis Services) then you should consider using the modern get data experience which has native Cosmos DB integration that's a lot more polished.