> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdv/integration/db/integration/mssql.md).

# ❖ MSSQL

This page describes how to integrate with your Microsoft SQL database.

{% hint style="info" %}
❖ **SDV Enterprise Bundle**. This feature is available as part of the **AI Connectors Bundle**, an optional add-on to SDV Enterprise. For more information, please visit the [AI Connectors Bundle](/sdv/explore/sdv-bundles/ai-connectors.md) page.
{% endhint %}

## Installation

To use this feature, please make sure you have installed the bundle with the optional `db-mssql` dependency. For more information, see the [SDV Enterprise Installation docs](https://docs.sdv.dev/sdv-enterprise/installation/instructions).

```bash
pip install sdv-installer --upgrade
sdv-installer install --package bundle-ai-connectors --options db-mssql
```

Microsoft SQL also requires that you have the ODBC Driver installed on your machine. For more information, see instructions from Microsoft for [Windows](https://learn.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server?view=sql-server-ver16), [MacOS](https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver16), and [Linux](https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16\&tabs=alpine18-install%2Calpine17-install%2Cdebian8-install%2Credhat7-13-install%2Crhel7-offline).

## Connector

&#x20;Create a connector object that interacts with your MSSQL database.

```python
from sdv.io.database import MSSQLConnector

connector = MSSQLConnector()
```

**Parameters** (None)

**Output** A connector object that you can use to import data and metadata

## Config File

Create a YAML file that corresponds to the database to connect to. You will need separate config files for your source dataset (for importing training data) and a destination dataset (for exporting synthetic data).

The config file has the following structure:

```yaml
connection:
  host: <string>
  port: <string>
  database_name: <string> 
  schema_name: <string>

auth:
  username: <string>
  password: <string>

runtime:
  connection_timeout: <int>

options.MSSQLConnector:
  encrypt: <true | false>
  trust_server_certificate: <true | false>
  max_pool_size: <int>
```

**Parameters**:

**`connection`**: This section defines the database tables you want to connect to. It is common to all traditional, self-managed databases that are not managed by a Cloud vendor.

* (required) `host`: The network address of the system running the database service. Based on your db setup, this can be a hostname (eg. [db.example.com](http://db.example.com)) or an IP address (eg. 10.0.0.1)
* (required) `port`: The network endpoint on the host where the database service listens for client connections. This is a numeric identifier but please provide it as a string.
* (required) `database_name`: A top-level logical container for data and database objects within a database system.
* (required) `schema_name`: A named logical grouping of database objects within a database, used for organization and access control.

**`auth`:** This section provides information about your identity, which is required to connect to the database.  It is common to all traditional, self-managed databases that are not managed by a Cloud vendor.

* (required) `username`: The identifier of who is authenticating the connection.
* (required) `password`: A secret credential associated with the username, used to verify its identity during authentication

**`runtime`**: This section contains other parameters that come into play during runtime, either when establishing the connection or running additional queries.  It is common to all traditional, self-managed databases that are not managed by a Cloud vendor.

* `connection_timeout`:  The maximum amount of time a client will wait while attempting to establish a connection to the database before stopping the attempt. This applies when first establishing the connection, not for any subsequent queries or timeouts.
  * (default) Driver and environment dependent, typically between \~10-30 seconds, but potentially unbounded.

**`options.MSSQLConnector`**: This section includes information that is specific for MSSQL databases

* `encrypt`: Specifies whether the connection between the client (SDV) and the database server is encrypted.&#x20;
  * (default) `true`: Encrypt all data transmitted over the network between the client and server, including authentication credentials and query/result traffic.
  * `false`: Do not encrypt
* `trust_server_certificate`: In the case that encryption is turned on, this parameter controls whether the client (SDV) verifies the identity of the database server when establishing an encrypted connection.
  * (default) `false`: The client (SDV) validates the certificate (recommended, secure)
  * `true`: The client (SDV) skips validation. Encryption still happens, but identity is not verified.&#x20;
* `max_pool_size`: The maximum number of database connections that the application (SDV) is allowed to keep open at the same time.
  * (default) 100

{% hint style="info" %}
**MSSQL terminology** may be different from the above parameters names, which are generic for databases.

* MSSQL typically refers to the `host` as the `server`. This is the same concept.
* If you have not set up a `schema_name` explicitly, use the one that MSSQL assigns by default. This is usually `dbo`. *For more info, see the* [*Microsoft docs*](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/ownership-and-user-schema-separation?view=sql-server-ver16#the-dbo-schema)*.*
  {% endhint %}

## Setting Your Config File

Use the `set_import_config` and `set_export_config` functions to add your config YAML file to your connector.

```python
connector.set_import_config(filepath='source_db_config.yaml')
connector.set_export_config(filepath='destination_db_config.yaml')
```

Use the connector to create metadata, import a subset of training data, and export synthetic data. For more information, see the [Usage API](/sdv/integration/db/api.md).

## FAQ

<details>

<summary>Which permissions are needed for importing and exporting?</summary>

**Importing data requires read access.** For MSSQL, you will need to have the `db_datareader` role.

**Exporting data requires write access.** For MSSQL, you will need to have the `db_datawriter`. If you'd like to overwrite data, then you'd need additional permissions given by the `db_ddladmin`, `db_owner`, or `sysadmin` roles.

For more information, see the [Microsoft documentation](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles?view=sql-server-ver16).

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sdv.dev/sdv/integration/db/integration/mssql.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
