Skip to content

Commit 42626df

Browse files
More improvements
1 parent 0df481d commit 42626df

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

articles/synapse-analytics/sql/query-cosmos-db-analytical-store.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,50 +34,63 @@ This article explains how to write a query with a serverless SQL pool that queri
3434
## Overview
3535

3636
Serverless SQL pool enables you to query Azure Cosmos DB analytical storage using `OPENROWSET` function.
37-
- `OPENROWSET` that uses workspace managed identity to access the analytical store.
38-
- `OPENROWSET` with inline key. This syntax can be used to query Azure Cosmos DB collections without the need to prepare credentials.
39-
- `OPENROWSET` that references a credential that contains the Azure Cosmos DB account key. This syntax can be used to create views on Azure Cosmos DB collections.
40-
41-
### [OPENROWSET with key or managed identity](#tab/openrowset-key)
42-
43-
To support querying and analyzing data in an Azure Cosmos DB analytical store, a serverless SQL pool is used. The serverless SQL pool uses the `OPENROWSET` SQL syntax, so you must first convert your Azure Cosmos DB connection string to this format:
4437

4538
```sql
4639
OPENROWSET(
4740
'CosmosDB',
4841
'<SQL connection string for Azure Cosmos DB>',
49-
<Container name>
42+
<other parameters>
5043
) [ < with clause > ] AS alias
5144
```
5245

5346
The SQL connection string for Azure Cosmos DB includes the following components:
54-
- **Account Name** - The name of the Azure Cosmos DB account you are targeting.
55-
- **Database Name** - The container name, specified without quotation marks in the OPENROWSET syntax. If the container name contains special characters (for example, a dash -), it should be enclosed in square brackets ([]).
56-
- **Region Name** (optional) - The region of your CosmosDB analytical storage. If omitted, the container's primary region is used.
57-
- **AuthType** - set this option to `ManagedIdentity` if accessing CosmosDB using the Synapse workspace Managed Identity instead of the account key.
58-
- **Key** - The master key for accessing CosmosDB data, used if not utilizing the Synapse workspace managed identity.
59-
- **Endpoint** (optional) - required if your CosmosDB account does not follow the standard `*.documents.azure.com` format.
47+
- **account** - The name of the Azure Cosmos DB account you are targeting.
48+
- **database** - The container name, specified without quotation marks in the OPENROWSET syntax. If the container name contains special characters (for example, a dash -), it should be enclosed in square brackets ([]).
49+
- **region** (optional) - The region of your CosmosDB analytical storage. If omitted, the container's primary region is used.
50+
- **endpoint** (optional) - required if your CosmosDB account does not follow the standard `*.documents.azure.com` format.
6051

61-
Some of this information can be derived from the standard Azure Cosmos DB connection string:
52+
> [!IMPORTANT]
53+
> The `endpoint` parameter is needed for accounts that don't match the standard `*.documents.azure.com` format. For example, if your Azure Cosmos DB account ends with `.documents.azure.us`, make sure that you add `endpoint=<account name>.documents.azure.us` in the connection string.
6254
55+
These properties can be identified from the standard CosmosDb connection string, for example:
6356
```
6457
AccountEndpoint=https://<database account name>.documents.azure.com:443/;AccountKey=<database account master key>;
6558
```
6659

6760
The SQL connection string can be formatted as follows:
68-
- Using the CosmosDB database account master key for authentication:
6961
```sql
70-
'account=<database account name>;database=<database name>;region=<region name>;key=<database account master key>'
62+
'account=<database account name>;database=<database name>;region=<region name>'
7163
```
7264

73-
- Using the workspace managed identity instead of the CosmosDB account key:
65+
This connection string does not include the authentication information required to connect to CosmosDB analytical storage. Additional information is needed depending on the type of authentication used:
66+
- If `OPENROWSET` uses workspace managed identity to access the analytical store, you should add the `AuthType` property.
67+
- If `OPENROWSET` uses an inline account key, you should add the `key` property. This allows you to query Azure Cosmos DB collections without needing to prepare credentials.
68+
- Instead of including authentication information in the connection string, `OPENROWSET` can reference a credential that contains the Azure Cosmos DB account key. This approach can be used to create views on Azure Cosmos DB collections.
69+
70+
These options are described below.
71+
72+
### [OPENROWSET with key or managed identity](#tab/openrowset-key)
73+
74+
To support querying and analyzing data in an Azure Cosmos DB analytical store, a serverless SQL pool is used. The serverless SQL pool uses the `OPENROWSET` SQL syntax, so you must first convert your Azure Cosmos DB connection string to this format:
75+
7476
```sql
75-
'account=<databases account name>;database=<database_name>;authtype=ManagedIdentity'
77+
OPENROWSET(
78+
'CosmosDB',
79+
'<SQL connection string for Azure Cosmos DB>',
80+
<Container name>
81+
) [ < with clause > ] AS alias
7682
```
83+
In addition to the common properties in the SQL connection string that are described above (**acount**, **database**, **region**, and **endpoint**), in this case, you need to add **one** of the following options:
84+
- **AuthType** - set this option to `ManagedIdentity` if accessing CosmosDB using the Synapse workspace Managed Identity.
85+
- **key** - The master key for accessing CosmosDB data, used if not utilizing the Synapse workspace managed identity.
7786

78-
> [!IMPORTANT]
79-
> There's another optional parameter in connection string called `endpoint`. The `endpoint` param is needed for accounts that don't match the standard `*.documents.azure.com` format. For example, if your Azure Cosmos DB account ends with `.documents.azure.us`, make sure that you add `endpoint=<account name>.documents.azure.us` in the connection string.
87+
The examples of connection strings are shown in the following table:
8088

89+
| Authentication type | Connection string |
90+
| --- | --- |
91+
| CosmosDB database account master key | `account=<account name>;database=<db name>;region=<region name>;key=<account master key>` |
92+
| Synapse workspace managed identity | `account=<account name>;database=<db name>;region=<region name>;authtype=ManagedIdentity` |
93+
```
8194
8295
### [OPENROWSET with credential](#tab/openrowset-credential)
8396

0 commit comments

Comments
 (0)