[Yandex Cloud documentation](../../../index.md) > [Yandex DataLens](../../index.md) > Connections > Databases > Creating a YDB connection

# Creating a connection to YDB from Yandex DataLens

{% note info %}


To create a connection, you will need a [service account](../../../iam/concepts/users/service-accounts.md) with the **ydb.viewer** or **viewer** [role](../../../iam/operations/sa/assign-role-for-sa.md).


To write subqueries in datasets and queries in QL charts, use the [YQL syntax](https://ydb.tech/docs/en//yql/reference/syntax/).

{% endnote %}

To create a YDB connection:


1. Open the [connection creation page](https://datalens.ru/connections/new).
1. Under **Files and services**, select the **YDB** connection.
1. Configure the connection as follows:

   
   * **Cloud and folder**: Select the folder where your service account will be located.
   * **Service account**: Select an existing service account or create a new one.
   * **Database**: Select the database to connect or create a new one.


   {% note warning %}

   Capital letters are not allowed in YDB database column names.

   {% endnote %}

   * **Cache TTL in seconds**: Specify the cache TTL or leave the default value. The recommended value is 300 seconds (5 minutes).
   
   * **Raw SQL level**: Enables you to use an ad-hoc SQL query to [generate a dataset](../../dataset/settings.md#sql-request-in-datatset). This option is disabled by default. When enabling it, you will need to select the raw SQL level:
   
      * **Allow subqueries in datasets**: Describe dataset sources using [SQL queries](../../dataset/settings.md#sql-request-in-datatset).
      * **Allow subqueries in datasets and source parameterization**: Describe dataset sources using SQL queries and use [source parameterization](../../dataset/settings.md#parametrization).
      * **Allow subqueries in datasets, source parameterization, and QL charts**: Describe dataset sources using SQL queries, use source parameterization, and [create QL charts](../../concepts/chart/ql-charts.md).

   
   ![image](../../../_assets/datalens/operations/connection/connection-ydb.png)



1. Optionally, test the connection by clicking **Check connection**.
1. Click **Create connection**.


1. Select the [workbook](../../workbooks-collections/index.md) to save your connection to or create a new one. If using legacy folder navigation, select a folder to save the connection to. Click **Create**.


1. Enter a name for the connection and click **Create**.


{% cut "RESOURCE_EXHAUSTED error" %}

If the Managed Service for YDB [quotas and limits](../../../ydb/concepts/limits.md) are exceeded, you may get the [`RESOURCE_EXHAUSTED`](../../../ydb/faq.md#resource-exhausted) error message. To avoid the error, follow these recommendations:

* Reduce the query rate. To achieve this, you can use filters or specify only the required chart fields to limit the amount of data you get.
* Follow the recommendations for database [query optimization](../../concepts/optimization_recommendations.md).
* Use the DataLens [chart inspector](../../concepts/chart/inspector.md) to assess the data amount and upload time.
* Check the Managed Service for YDB monitoring charts for exceeded quotas and limits. If you need to, you may slightly [increase](../../../ydb/operations/manage-databases.md#update-db-serverless) the [throughput capacity](../../../ydb/concepts/serverless-and-dedicated.md#capacity) (request units, RUs) limit under **Limits**.

{% note info %}

Increasing the throughput limit in the serverless database settings may result in high usage costs. Since serverless database resources are indefinitely large, the maximum consumption of RUs over a period of time can also reach any value, leading to excessive charges. When changing it, increase the value by only a very small amount, e.g., by 10 RUs per second.

{% endnote %}

{% endcut %}