Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/cmd/runtime/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
_ "github.com/rilldata/rill/runtime/drivers/slack"
_ "github.com/rilldata/rill/runtime/drivers/snowflake"
_ "github.com/rilldata/rill/runtime/drivers/sqlite"
_ "github.com/rilldata/rill/runtime/drivers/sqlserver"
_ "github.com/rilldata/rill/runtime/drivers/starrocks"
_ "github.com/rilldata/rill/runtime/reconcilers"
_ "github.com/rilldata/rill/runtime/resolvers"
Expand Down
9 changes: 9 additions & 0 deletions docs/docs/developers/build/connectors/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Rill is continually evaluating additional OLAP engines that can be added. For a
## Databases
### MySQL
### PostgreSQL
### SQL Server
### SQLite

<div className="connector-icon-grid">
Expand All @@ -157,6 +158,14 @@ Rill is continually evaluating additional OLAP engines that can be added. For a
linkLabel="Learn more"
referenceLink="postgresql"
/>
<ConnectorIcon
icon={<img src="/img/build/connectors/icons/Logo-SQLServer.svg" alt="SQL Server" className="large-icon"/>}
header="SQL Server"
content="Connect to Microsoft SQL Server databases with support for encryption and various authentication methods."
link="/developers/build/connectors/data-source/sqlserver"
linkLabel="Learn more"
referenceLink="sql-server"
/>
<ConnectorIcon
icon={<img src="/img/build/connectors/icons/Logo-SQLite.svg" alt="SQLite" />}
header="SQLite"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Rill supports connecting your data to both [DuckDB](/developers/build/connectors
## Databases
### MySQL
### PostgreSQL
### SQL Server
### SQLite

<div className="connector-icon-grid">
Expand All @@ -102,6 +103,14 @@ Rill supports connecting your data to both [DuckDB](/developers/build/connectors
linkLabel="Learn more"
referenceLink="postgresql"
/>
<ConnectorIcon
icon={<img src="/img/build/connectors/icons/Logo-SQLServer.svg" alt="SQL Server" className="large-icon"/>}
header="SQL Server"
content="Connect to Microsoft SQL Server databases with support for encryption and various authentication methods."
link="/developers/build/connectors/data-source/sqlserver"
linkLabel="Learn more"
referenceLink="sql-server"
/>
<ConnectorIcon
icon={<img src="/img/build/connectors/icons/Logo-SQLite.svg" alt="SQLite" />}
header="SQLite"
Expand Down
143 changes: 143 additions & 0 deletions docs/docs/developers/build/connectors/data-source/sqlserver.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
title: SQL Server
description: Connect to data in SQL Server
sidebar_label: SQL Server
sidebar_position: 45
---

import { TwoStepFlowIntro, EnvPullTip, DevProdSeparation, DeployToCloud } from '@site/src/components/connector';

{/* WARNING: There are links to this page in source code. If you move it, find and replace the links and consider adding a redirect in docusaurus.config.js. */}

## Overview

[Microsoft SQL Server](https://learn.microsoft.com/en-us/sql/sql-server/) is a relational database management system developed by Microsoft. It supports a wide range of applications, from small projects to large enterprise systems, with features like advanced analytics, in-memory processing, and robust security. You can connect to and read from SQL Server databases directly.

## Authentication Methods

To connect to SQL Server, you need to provide database connection credentials. Rill supports connecting via individual parameters (host, port, user, password, database).

<TwoStepFlowIntro
connector="SQL Server"
step1Description="Set up your SQL Server connector with connection credentials (host, port, user, password, database)"
step2Description="Define which table or query to execute"
/>

### Connection String Format

When connecting to SQL Server, you can also specify a Data Source Name (DSN) using the following syntax:

```bash
mssql://<user>:<password>@<host>:<port>/<database>
```

- **scheme**: Use `mssql` for SQL Server connections.
- **user** and **password**: Should correspond to the user credentials that Rill will use to connect to SQL Server.
- **host** and **port**: Should correspond to the hostname and port (default 1433) of your SQL Server instance.
- **database**: Should correspond to the database in SQL Server that you are using.

For special characters in the password, percent-encode them (e.g., `@` becomes `%40`, `:` becomes `%3A`):
```text
mssql://user:pa%40ss@localhost:1433/my-db # password contains '@'
mssql://user:pa%3Ass@localhost:1433/my-db # password contains ':'
```

For more details, see the [go-mssqldb connection string documentation](https://github.com/microsoft/go-mssqldb#connection-parameters-and-dsn).

## Method 1: Connection Credentials

### Using the UI

1. Click **Add Data** in your Rill project
2. Select **SQL Server** as the data source type
3. In the authentication step:
- Enter your SQL Server host and port
- Enter your database name
- Enter your username and password
- Configure encryption if needed
4. In the data model configuration step, enter your SQL query
5. Click **Create** to finalize

After the model YAML is generated, you can add additional [model settings](/developers/build/models/source-models) directly to the file.

### Manual Configuration

If you prefer to configure manually:

**Step 1: Create connector configuration**

Create `connectors/sqlserver.yaml`:

```yaml
type: connector
driver: sqlserver

host: "localhost"
port: 1433
database: "mydatabase"
user: "myusername"
password: "{{ .env.SQLSERVER_PASSWORD }}"
encrypt: false
```

**Step 2: Add credentials to `.env`**

```bash
SQLSERVER_PASSWORD=your-secure-password
```

<EnvPullTip />

Then, [create your first model](#create-your-first-model).

## Method 2: DSN Connection String

You can also configure the connector using a single DSN connection string instead of individual parameters.

Create `connectors/sqlserver.yaml`:

```yaml
type: connector
driver: sqlserver

dsn: "{{ .env.SQLSERVER_DSN }}"
```

Add the DSN to your `.env` file:

```bash
SQLSERVER_DSN=mssql://myusername:mypassword@localhost:1433/mydatabase
```

<EnvPullTip />

Then, [create your first model](#create-your-first-model).

## Create Your First Model

Once your connector is configured, create a model to define what data to pull.

Create `models/sqlserver_data.yaml`:

```yaml
type: model
connector: sqlserver
dev:
sql: SELECT TOP 10000 * FROM my_table

sql: SELECT * FROM my_table
```

After creating the model, you can add additional [model settings](/developers/build/models/source-models) directly to the file.

## Separating Dev and Prod Environments

<DevProdSeparation />

## Deploy to Rill Cloud

<DeployToCloud
connector="SQL Server"
connectorId="sqlserver"
credentialDescription="the SQL Server connection credentials"
/>
64 changes: 64 additions & 0 deletions docs/docs/reference/project-files/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,70 @@ dsn: "{{ .env.SNOWFLAKE_DSN }}" # define SNOWFLAKE_DSN in .env file
parallel_fetch_limit: 2
```

## SQL Server

### `driver`

_[string]_ - Refers to the driver type and must be driver `sqlserver` _(required)_

### `dsn`

_[string]_ - SQL Server Connection String in [mssql URI format](https://learn.microsoft.com/en-us/sql/connect/ado-net/connection-string-syntax).
```text
mssql://user:password@host:1433/my-db
```
Rules for special characters in password:
- The following characters are allowed [unescaped in the URI](https://datatracker.ietf.org/doc/html/rfc3986#section-2.3): `~` `.` `_` `-`
- All other special characters must be percent-encoded (`%XX` format).


### `user`

_[string]_ - Username for authentication

### `password`

_[string]_ - Password for authentication

### `host`

_[string]_ - Hostname or IP address of the SQL Server instance

### `port`

_[string]_ - Port number for the SQL Server instance (default is 1433)

### `database`

_[string]_ - Name of the SQL Server database to connect to

### `encrypt`

_[boolean]_ - Encrypt the connection using TLS

### `log_queries`

_[boolean]_ - Enable logging of all SQL queries (useful for debugging)

```yaml
# Example: SQL Server connector configured using individual properties
type: connector
driver: sqlserver
host: localhost
port: 1433
database: mydatabase
user: myusername
password: "{{ .env.SQLSERVER_PASSWORD }}"
encrypt: false
```

```yaml
# Example: SQL Server connector configured using dsn
type: connector
driver: sqlserver
dsn: "{{ .env.SQLSERVER_DSN }}" # Define DSN in .env file
```

## SQLite

### `driver`
Expand Down
4 changes: 4 additions & 0 deletions docs/src/css/_connector-icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ h3:has(~ div.component-icon-grid) {
vertical-align: middle;
}

.large-icon {
height: 4rem !important;
}

.sheets-icon {
height: 3rem !important;
}
Expand Down
Loading
Loading