How to connect CosmosDB with SharePoint

This "how-to-connect" documentation will explain the initial configuration of an example connection from CosmosDB to a SharePoint Online List in Office 365. We will be synchronizing data stored in CosmosDB.

 

This guide presupposes that you have installed the Layer2 Cloud Connector and that you are familiar with its basic functionality. The Layer2 Cloud Connector User Documentation will provide you with all necessary information.

 

 

Contents

1. Configuring CosmosDB

2. Configuring the Layer2 Cloud Connector

2.1 Creating a new connection

2.2 Configuring the Data Entity 1

2.3 Configuring the Data Entity 2

2.4 Running your connection

3. Hints and known issues

3.1 Connection direction

3.2 Data model

3.3 Batch operations

 

1. Configuring CosmosDB

Go to your Azure account and to your CosmosDB. Go to Keys and copy your URI and primary key:

 

CosmosDB Keys

 

You will need the name from the database and the collection name too. Go to Azure Cosmos DB and click on your database to see the URI:

 

CosmosDB uri

 

2. Configuring the Layer2 Cloud Connector

2.1. Creating a new connection

Create a new connection by using the Create New Connection option in the Actions pane (right-hand side). The new connection will appear at the bottom of the Connection Manager List (left-hand side). Click on your newly created connection to open the connection configuration settings.

 

Choose a meaningful name for your connection and replace the current "New Connection" Connection Title with it.

 

Connections to CosmosDB can be bi-directional. An initial connection should always be uni-directional to assure that both data entities are identical before switching to bi-directional. Therefore, choose Left to Right as Direction. You can change this setting after your initial synchronisation finished successfully.

 

 

Step 1 CosmosDB connection setup uni

 

 

 

2.2. Configuring the Data Entity 1

We will now set up our Data Entities. Go to the data entity “Data Entity 1” to open the configuration settings.

 

Choose a Data Entity Title. It is recommended to give your entities meaningful names to maintain an overview when you decide to set up multiple connections.

 

Select the Data Provider for CosmosDB from the data provider list. You can search for CosmosDB by typing into the selection box.

 

 

Step 2 CosmosDB integration source setup.png

 

For the Connection String, we need the in step 1 mentioned information. You can copy the below connection string and adjust it to match your gathered information. Use the Verify Connection String option to evaluate if the provided connection string is valid.

 

 

AccountEndpoint=https://company.documents.azure.com:443/;AccountKey=youraccountkey;FlattenArrays=1;

 

 

  • "AccountEndpoint=youraccountendpoint;" this property must be set to your account end point from step 1.
  • "AccountKey=youraccountkey;" this property must be set to your account key from step 1.
  • "FlattenArrays=1;" this property can be used to flatten the elements of nested arrays into columns of their own. It is an optional parameter that delivers the best results for us if set to 1. 

 

 

The Select Statement text box is used to define specific data queries. We will be gathering all data from our database. You can copy the below select statement and adjust it to match your needs. Save your changes by using the right-hand pane option Save Changes.

 

SELECT * FROM layercollection

 

 

Step 2.5 CosmosDB integration connection string setup.png

 

To check if all necessary columns are received, you can use the Preview Data option on the right-hand pane which will provide you with a pop-up window showing your sample data from your CosmosDB entity.

 

 

Preview data of CosmosDB integration.png

 

2.3. Configuring the Data Entity 2

We are going to send the data to a custom SharePoint Online list. It's required that you set up this list prior to the next steps. Your list should contain matching columns according to your source entity.

 

Use the left-hand pane to switch to the data entity "Data Entity 2". We will be using the Layer2 SharePoint Provider for this setup. 

 

For more information about the SharePoint provider visit:

https://www.layer2solutions.com/support/cloud-connector-faqs/layer2-csom-sharepoint-ado-net-provider.

 

You can copy the below Connection String which contains the minimum of required properties to connect to your custom SharePoint Online list.

 

URL=https://your_custom_sharepoint_list_url/AllItems.aspx;Authentication=Microsoft_Modern;

 

  • "URL=https://your_custom_sharepoint_url/AllItems.aspx;" this property defines the URL of your custom list that will be addressed.
  • "Authentication=Microsoft_Modern;" this property will determine the authentication method used. Microsoft_Moddern is the default authentication method to access Microsoft Office 365 / SharePoint Online and should work in most cases, even if the SharePoint site is connected to an ADFS. This authentication does not need any further connection string settings, other than the URL of the connected system.

 

Enter the password that belongs to the user account used in the connection string into the Password field. Save your changes by using the right-hand pane option Save Changes.

 

 

Step 3 CosmosDB integration target setup.png

 

In the next step, we will configure our mapping settings. Click on the Mappings option on the left-hand pane. If your fields from SharePoint are named identical to the fields from your source system, the Enable Auto Mapping option will match those columns. Disabling this option allows you to match your columns as needed. Save your changes by using the right-hand pane option Save Changes.

 

Step 4 CosmosDB integration mapping.png

 

2.4. Running your connection

To run your connection switch back to the main connection configuration node and use the Run Now Button located on the bottom of the setup page. The Run Synchronization Toolbox will also display the synchronization process. 

 

Step 5 CosmosDB data integration start.png

 

Below is a data preview of the information we have accessed in our source entity:

 


CosmosDB integration ready.png

 

This will be the result in our SharePoint Online list after our initial successful synchronization:

 


Finished CosmosDB integration.png

If you want to use a bi-directional syncronization, you can now switch your connection directon after our first initial synchronization run finished successfully. See section 3.1 for further information.

3. Hints and known issues

 

3.1. Connection direction

As far as tested, this connection supports uni-directional as well as bi-directional synchronizations. 

 

After adjusting the direction to bi-directional, you should check your Mappings settings again because some systems might include read-only columns that cannot be mapped directly.

 

We also recommend to choose a Conflict Resolution that matches your environments needs. You can find out more about the different conflict resolutions in our Layer2 Cloud Connector User Documentation.

3.2. Data model

To see all the tables and views you can access with the CosmosDB provider, use these queries in the Select Statement:

 

 

SELECT * FROM sys_tables

 

SELECT * FROM sys_views

 

 

If there are more tables or views available, you can load them with the option "load more" in the popup window.

3.3. Batch operations

If you try to make multiple operations at the same time, you can get an error that batch operations not allowed. Set the parameter Other=’BatchSize=1’ in your connection string to avoid this error. 

 

 

↑Top

Search for more data integration & synchronization solutions

Icon of Contact us - Chat - Layer2 leading solutions

Questions?

Contact us directly to discuss your specific requirements, help you with purchasing, or with any other questions.

 

Icon for Layer2 Solutions Finder- Layer2 leading solutions

About the Layer2 Cloud Connector

Get more information about the Layer2 Cloud Connector on the product page.

 

 

Icon for Layer2 Solutions Finder- Layer2 leading solutions

Try it out for 15 days

Get a free trial of the Layer2 Cloud Connector after a short registration.