Thu, 06/25/2020 - 22:21 By Stéphan Drouard
3 comments
How to access the Dynamics 365 online SQL Server database

Connect to Dynamics 365 database

EDIT : You can also query Dynamics 365 / CDS SQL Server by using C# with this article

Presentation

A new feature is coming this year and is only available as preview for the moment. You are now able to connect your Dynamics 365 database. This SQL connection provides a read-only access to the CDS environment. You can see each column type of each entity and you can execute SQL request directly in the databases.

Prerequisites

Check your environment version

As I said in the prerequisites, your environment you want to access must have at least version 9.1.0.17437.

To verify that, go to your environment (https://********.crm4.dynamics.com), Settings -> About

1

Here you can see the server version

2

If the version is higher than 9.1.0.17437, we can go to the next step.

Enables Tabular Data Stream (TDS) endpoint 

This option is only available for environments enabled for this public preview and with a recent version.

I advise to use Internet Explorer to do it.

To enable it, go to your environment list in the Power Platform admin center -> https://admin.powerplatform.microsoft.com/environments

From there, select your environment and open its settings.

3

In the Settings page, open up the Product section and click on Features

4

If the link doesn't work, you can make it yourself.

First, take the id of your environment in the url:

5

Then generate the Features link: https://admin.powerplatform.microsoft.com/environments/yourenvironmentid/settings/Features

You can easily activate the TDS from this page:

6

Now you can access your datas as read-only.

We will see how to connect using Microsoft Sql Server Management studio or Power BI Desktop, depending what you prefer.

Using Microsoft Sql Server Management studio

Open your Microsoft Sql Server Management studio and connect to your environment.

  • Server Type: Database Engine
  • Server name: your crm url and the port 5558 separated with a comma -> ********.crm4.dynamics.com,5558
  • Authentication: Azure Active Directory - Password
  • User name: your admin username
  • Password: your admin password

7

Click on Connect.

8

Now you are connected, you can access the database in read-only mode.

Following the user you are connected with, you will be limited to request the entities you have the read right set in the CRM.

You can use SQL to request the database.

Be aware that not all operation are supported within this feature. You can only use the following:

  • SELECT
  • UNION
  • JOIN
  • FILTER
  • Batch operations 
  • Aggregate operations like COUNT() and MIN() or MAX()

 

Performance

On the following link, a performance comparison has been done between the FetchXML Builder add-on for the XrmToolBox and the T-SQL.

The performance will really depend on the query you are running, the number of column you are requesting.

Read the Joe D365 article which really well explains the tests and gives great conclusions about them.

 

Using Power BI Desktop

To open your database through Power BI Desktop, we will generate a pbids file in Power Apps.

Connect to Power Apps, then go to Data -> Entities

Then download the pbids file clicking on Analyse in Power BI

9

Now, double click on the downloaded file. it should be opened with Power BI Desktop.

You will be asked to sign in with your credentials:

10

Once signed-in, you have now access in read-only to all your tables. 

11

As you can notice in the application, the storage mode used is Direct Query. It means that data are loaded in real-time!

Following the user you are connected with, you will be limited to request the entities you have the read right set in the CRM.

You can start working with them.

Limitations

  • This is a preview feature and you're not supposed to use it for a production environment.
  • The databases are only accessible in read-only mode.
  • Not every operation are available in SQL within this feature.

 

Comments

Very good explanation. However, I don't understand the difference between an oData access via Powerbi and a Tabular Data Stream access.

Moreover, I don't have Use Azure Active Directory authentication under Sql

Have a nice day!

Thu, 01/07/2021 - 08:16
François (not verified)

Hi Stephan, I loved your post this is well explained and useful
I was unable to connect Microsoft Sql Server Management studio by appending port number to the org url
where as when i tried only by org url it worked, Also can you please help me that from where did you get port number?

Fri, 04/09/2021 - 08:19
Meghna Kharera (not verified)

Hi Meghna, this port are coming from the official MS documentation wherein they say : 

Ports 1433 and/or 5558 need to be enabled to use the TDS endpoint from a client application such as SSMS. If you only enable port 5558, the user must append that port number to the server name in the Connect to Server dialog of SSMS - for example: myorgname.crm.dynamics.com;5558.

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/dataverse-sql-query

Fri, 04/09/2021 - 17:45

In reply to by Meghna Kharera (not verified)

Add new comment

Image CAPTCHA
Enter the characters shown in the image.