---
title: "Get a Per-Database Connection String"
url: "https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings"
version: "7.2"
language: "python"
---

# Get a Per-Database Connection String

> Client language: Python. Also available for [C#](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings.md), [Java](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings.java.md), [Node.js](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/get-connection-strings.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - Use `GetConnectionStringsOperation` to retrieve a specific connection string,  
>   or all connection strings defined in the database.
>
> - This operation reads connection strings from a single database's record.  
>   To get connection strings defined at the cluster level, see [Get server-wide connection strings](https://docs.ravendb.net/7.2/integrations/connection-strings/server-wide/get-connection-strings.md).
>
> - Learn more about per-database connection strings in [Per-database connection strings - Overview](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/overview.md).  
>   To create or update a connection string, see [Add or update a connection string](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/add-or-update-connection-string.python.md).
>
> - In this article:
>   - [Get connection string by name and type](#get-connection-string-by-name-and-type)
>   - [Get all connection strings](#get-all-connection-strings)
>   - [Syntax](#syntax)

## Get connection string by name and type {#get-connection-string-by-name-and-type}

The following example retrieves a `Raven` connection string in the current database:

```python
from ravendb.documents.operations.connection_string.get_connection_string_operation import GetConnectionStringsOperation
from ravendb.serverwide.server_operation_executor import ConnectionStringType

# Request a specific connection string, pass its name and type:
# =============================================================
get_raven_con_str_op = GetConnectionStringsOperation(
    "ravendb-connection-string-name", ConnectionStringType.RAVEN)

connection_strings = store.maintenance.send(get_raven_con_str_op)

# Access results:
# ===============
raven_connection_strings = connection_strings.raven_connection_strings

# If no connection string matches the specified name and type, 
# the result dictionary is None.
if raven_connection_strings is not None:
    number_of_raven_connection_strings = len(raven_connection_strings)
    raven_con_str = raven_connection_strings["ravendb-connection-string-name"]

    target_urls = raven_con_str.topology_discovery_urls
    target_database = raven_con_str.database
```

## Get all connection strings {#get-all-connection-strings}

The following example retrieves all connection strings defined in the database:

```python
from ravendb.documents.operations.connection_string.get_connection_string_operation import GetConnectionStringsOperation

# Get all connection strings:
# ===========================
get_all_con_str_op = GetConnectionStringsOperation()
all_connection_strings = store.maintenance.send(get_all_con_str_op)

# Access results by connection string type:
# =========================================

# Raven
raven_connection_strings = all_connection_strings.raven_connection_strings

# SQL
sql_connection_strings = all_connection_strings.sql_connection_strings

# OLAP
olap_connection_strings = all_connection_strings.olap_connection_strings

# Elasticsearch
elasticsearch_connection_strings = all_connection_strings.elastic_search_connection_strings

# Queue
queue_connection_strings = all_connection_strings.queue_connection_strings

# Snowflake
snowflake_connection_strings = all_connection_strings.snowflake_connection_strings

# AI
ai_connection_strings = all_connection_strings.ai_connection_strings
```

> **Note**
>
> A connection string type that has no connection strings defined for it is returned as `None`, not as an empty dictionary.
> Check for `None` before iterating over a result, for example:
>
> ```python
> if all_connection_strings.sql_connection_strings:
>     for name, con_str in all_connection_strings.sql_connection_strings.items():
>         print(name)
> ```

## Syntax {#syntax}

```python
class GetConnectionStringsOperation(MaintenanceOperation[GetConnectionStringsResult]):
    def __init__(self, connection_string_name: str = None,
                 connection_string_type: ConnectionStringType = None): ...
```

| Parameter | Type | Description |
| - | - | - |
| **connection\_string\_name** | `str` | Connection string name |
| **connection\_string\_type** | `ConnectionStringType` | Connection string type:<br />`RAVEN`, `SQL`, `OLAP`, `ELASTIC_SEARCH`, `QUEUE`, `SNOWFLAKE`, or `AI`<br />Required whenever `connection_string_name` is given. |

```python
class ConnectionStringType(enum.Enum):
    NONE = "None"
    RAVEN = "Raven"
    SQL = "Sql"
    OLAP = "Olap"
    AI = "Ai"
    ELASTIC_SEARCH = "ElasticSearch"
    QUEUE = "Queue"
    SNOWFLAKE = "Snowflake"
```

| Operation result | Description |
| - | - |
| `GetConnectionStringsResult` | Class holding all connection strings defined in the database. |

```python
class GetConnectionStringsResult:
    def __init__(
        self,
        raven_connection_strings: Dict[str, RavenConnectionString] = None,
        sql_connection_strings: Dict[str, SqlConnectionString] = None,
        olap_connection_strings: Dict[str, OlapConnectionString] = None,
        ai_connection_strings: Dict[str, AiConnectionString] = None,
        elastic_search_connection_strings: Dict[str, ElasticSearchConnectionString] = None,
        queue_connection_strings: Dict[str, QueueConnectionString] = None,
        snowflake_connection_strings: Dict[str, SnowflakeConnectionString] = None,
    ): ...
```

> **Note**
>
> Connection string type-specific fields and complete examples are documented in the task or feature articles listed under
> [Connection string per type](https://docs.ravendb.net/7.2/integrations/connection-strings/per-database/add-or-update-connection-string.python.md#connection-string-per-type).
