# Route a database connection with a user attribute (/core/build/security-and-governance/how-to/route-a-database-connection)

:::info
**Target Audience**: Makers & Developers
:::

## Goal [#goal]

Send each viewer's queries to their own data source through one connection. The steps use the **Database** field. Other fields that change which data is read work the same way.

## Prerequisites [#prerequisites]

- A connection field that accepts a variable and changes which data is read. The **Database** field does not redirect queries on MySQL.
- Sources that expose the same schemas, tables and columns.
- A backend that generates your embed tokens.

## Steps [#steps]

### 1. Add the user attribute [#1-add-the-user-attribute]

1. Go to **Users > User model**.
2. Under **Token Attributes**, click **Add attribute**.
3. Enter a **Name**, for example `db_name`, and select the **Text** type.
4. Click **Set default value** and type the value as is, without quotes. Use a source with no real tenant data.

### 2. Select the variable in the connection [#2-select-the-variable-in-the-connection]

1. Add or edit the database connection.
2. Next to **Database**, click **Variable** (`{}` icon).
3. Select `db_name`.

### 3. Test and save [#3-test-and-save]

Click **Test Connection**, then save. The test uses the default value, so it does not check the other sources.

### 4. Send the attribute in the embed token [#4-send-the-attribute-in-the-embed-token]

Call this endpoint from your server only.

```http
POST $PRODUCT_URL/embed/generate-token
x-api-key: <YOUR_API_KEY>
Content-Type: application/json

{
  "user": {
    "distinctId": "user-123",
    "role": "explorer",
    "attributes": { "db_name": "<VIEWER_DATABASE>" }
  }
}
```

If your user model has other custom attributes, include them too.

### 5. Check the routing [#5-check-the-routing]

Open a dashboard with tokens for two sources that hold different data. Each token must show only its own data, including filter values and AI answers.
