> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to MSSQL

This topic describes how to connect to a [Microsoft SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-2016) (MSSQL) from Domino. You must have network connectivity between Impala and your Domino deployment.

The easiest way to connect to MSSQL from Domino is to create a Domino Data Source as described below.

## Create a MSSQL Data Source

1. From the navigation pane, click **Data > Data Sources**.

2. Click **Create a Data Source**.

3. In the New Data Source window, from **Select Data Store**, select **SQL Server**.

4. Enter the **Host**. Valid values are `<host string>:3306` or `<host string>`.

5. Enter the **Port**.

6. Enter the name of the **Database**.

7. Enter the **Data Source Name**.

8. Optional: Enter a **Description** to explain the purpose of the Data Source to others.

9. Click **Next**.

10. Enter the **Username** and **Password** to connect to SQL Server. The Domino secret store backed by HashiCorp Vault securely stores the credentials.

11. Click **Test Credentials**.

12. If the Data Source authenticates, click **Next**.

13. Select who can view and use the Data Source in projects.

14. Click **Finish Setup**.

## Alternate way to connect to an MSSQL Data Source

<Warning>
  This section describes an alternate method to connect to the MSSQL Data Source. Domino does not officially support this method.
</Warning>

1. To interact with MSSQL databases from Python, Domino recommends the [pymssql](http://www.pymssql.org/) package.

2. Use the following Dockerfile instruction to [install pymssql](http://www.pymssql.org/intro.html) in your environment.

   This instruction assumes you already have [pip](https://pypi.org/project/pip/) installed.

   ```dockerfile theme={null}
   RUN pip install pymssql
   ```

3. You must set up the following Domino environment variables to store secure information about your MSSQL connection.

   * `DB_SERVER`

   * `DB_USERNAME`

   * `DB_PASSWORD`

     See [Store Project credentials](/cloud/platform-capabilities/core-concepts/projects/configure-projects/store-project-credentials) to learn more about Domino environment variables.

     See the [pymssql documentation](http://www.pymssql.org/pymssql_examples.html) for detailed information about how to use the package. The following is an example of connecting to MSSQL with Python where the following is true:

   * You have set up environment variables noted previously.

   * The server hosts a database named `myData` with a table named `addresses`.

     ```python theme={null}
     from os import getenv
     import pymssql

     server = getenv("DB_SERVER")
     user = getenv("DB_USERNAME")
     password = getenv("DB_PASSWORD")

     conn = pymssql.connect(server, user, password, "myData")
     cursor = conn.cursor()

     cursor.execute('SELECT * FROM addresses')
     row = cursor.fetchone()
     while row:
         print("ID=%d, Name=%s" % (row[0], row[1]))
         row = cursor.fetchone()

     conn.close()
     ```

### R and RODBC to MSSQL

1. To interact with MSSQL databases from R, Domino recommends the [RODBC](https://cran.r-project.org/web/packages/odbc/index.html) library. You can use an alternative package if you’d like.

2. Use the following Dockerfile instructions to add the MSSQL drivers to your Ubuntu 16.04 environment.

   ```dockerfile theme={null}
   USER root
   RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
   RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
   RUN apt-get update
   RUN ACCEPT_EULA=Y apt-get install msodbcsql17
   USER ubuntu
   ```

3. See Microsoft’s documentation for the Dockerfile instructions to add the MSSQL drivers to your Domino-supported Ubuntu environment.

4. See the [RStudio RODBC documentation](https://db.rstudio.com/databases/microsoft-sql-server/) for information about how to use the package.

## Next steps

* After connecting to your Data Source, learn how to [Use Data Sources](/cloud/platform-capabilities/core-concepts/data/data-source-connectors/use-data-sources).

* [Share this Data Source](/cloud/platform-capabilities/core-concepts/data/sharing-and-security/share-data-sources) with your collaborators.
