Skip to content

Connect SPSync to SQL Server

This guide covers SQL Server you run yourself (on-premises, on an Azure virtual machine, or Azure Arc-enabled SQL Server) and Amazon RDS for SQL Server. For Azure SQL Database and Azure SQL Managed Instance, read Azure SQL.

  • SQL Server with SQL authentication turned on (mixed mode), or a domain-joined SPSync machine for Windows integrated authentication. SPSync signs in with a login and password or, in integrated mode, as the machine’s own identity (integrated mode and the Entra modes are in preview, not verified against a real domain controller or a live Entra-enabled instance).
  • ODBC Driver 17 or 18 for SQL Server on the machine that runs SPSync. The desktop app and the Azure managed application include it. On a machine where you run the CLI, install Microsoft’s driver first.
  • A database that SPSync can own tables in. A dedicated database is the easy way to keep SPSync’s tables separate from everything else.

Create the database and a least-privilege user

Section titled “Create the database and a least-privilege user”

spsync destination grant-script --kind mssql --identity <name> --principal sql prints the schema and grant lines below for your own names. SPSync never runs them. The script below creates a database, a login, and a user that can create and use tables in two schemas and nothing else. sync is the schema SPSync loads into (the dataset_name) and sync_staging is the schema SPSync uses while it merges a round into the main tables. Run it as a member of sysadmin or equivalent. It comes from the SQL Server documentation and has not been run here against a test instance.

CREATE DATABASE spsync;
GO
CREATE LOGIN spsync_loader WITH PASSWORD = 'use-a-long-random-password', CHECK_POLICY = ON;
GO
USE spsync;
GO
CREATE USER spsync_loader FOR LOGIN spsync_loader;
GO
CREATE SCHEMA sync AUTHORIZATION spsync_loader;
GO
CREATE SCHEMA sync_staging AUTHORIZATION spsync_loader;
GO
GRANT CREATE TABLE, CREATE VIEW TO spsync_loader;
GO

Owning both schemas lets the login create, alter and drop tables in them. CREATE VIEW is only used if you switch on reporting views. Leave it out if you do not.

SPSync opens an outbound connection to the server on TCP port 1433, or the port you configured. Where SPSync runs decides what you open.

  • Desktop app or a self-hosted server: the connection starts from that machine, so a private address, a VPN or a local firewall rule for that machine is enough.
  • On-premises or an Azure virtual machine: allow inbound TCP 1433 from the machine that runs SPSync only. On an Azure VM, that is a rule on the network security group attached to the VM’s network interface or subnet.
  • Azure Arc-enabled SQL Server: the instance sits on your own network, so the on-premises rules apply.
  • Amazon RDS for SQL Server: add an inbound rule for port 1433 to the instance’s security group. Use the source address of the machine that runs SPSync, written as /32.
  • Azure managed application: it runs in your own Azure subscription. Allow the address it connects out from instead of opening the server to the internet, or put the server on the same virtual network.

SPSync opens every SQL Server connection with Encrypt=yes;TrustServerCertificate=no unless the string says otherwise, so the server’s certificate must be one the SPSync machine trusts. A self-hosted server usually has a self-signed certificate. Install a certificate from a CA the SPSync machine already trusts, or add the server’s CA to that machine’s trust store. As a last resort add TrustServerCertificate=yes and accept that SPSync then encrypts the connection without checking who answered. SPSync logs a warning on every run that does this, and spsync doctor and the Destination screen show it.

Amazon RDS for SQL Server presents a certificate that does not chain to a public root. Install the RDS CA bundle in the SPSync machine’s trust store.

ODBC Driver 18 has no setting for a CA file, so SPSync cannot take a pasted CA bundle for SQL Server, and a destination that has one is refused rather than ignored. What the Destination screen offers is the checkbox for the last resort above: clearing Verify the server certificate adds TrustServerCertificate=yes, with the same warning on every run, in Test connection and in spsync doctor.

If the database is reachable only through a jump host, SPSync can open an SSH tunnel to that host for each run, forward a local port to the database, and close the tunnel when the run ends. This is a preview: it is tested against a real SSH server in the SPSync test suite, but it has not been run against a SQL Server behind a customer’s jump host.

  1. On a machine you trust, read the jump host’s host key fingerprint. This prints a line containing SHA256: followed by 43 characters:

    Terminal window
    ssh-keyscan -t ed25519 bastion.example.com | ssh-keygen -lf -

    SPSync asks the server for an ed25519 host key first, then ECDSA, then RSA, so pin the fingerprint of the first of those the server has. If you are unsure, run ssh-keyscan without -t and pin every fingerprint it prints.

  2. In the connection string, give the database’s address as the jump host sees it, for example sql.internal:1433. SPSync rewrites the address to the local port while the tunnel is open; the string you save is not changed.

  3. On the Destination screen, tick Reach the database through an SSH bastion and fill in the host, port, user and fingerprint, then paste a private key (and its passphrase) or enter a password. The key is kept in the computer’s keychain and is not shown again.

  4. In the CLI, add an ssh_tunnel block to the destination in the config file, as below. export-config does not write it. With the admin MCP server, the assistant can set the host, port, user and fingerprint, and you enter the key or password on the secure entry page.

destination:
kind: mssql
connection_string_env: SPSYNC_DSN
ssh_tunnel:
host: bastion.example.com
port: 22 # optional, 22 by default
user: spsync
host_key_fingerprints:
- "SHA256:<the fingerprint from step 1>"
private_key_env: keychain:spsync/bastion-key # or file:/path/to/key, or an environment variable name
# passphrase_env: BASTION_KEY_PASSPHRASE # only if the key has one
# password_env: BASTION_PASSWORD # instead of private_key_env

The host key is always checked. If the jump host presents a key that is not in host_key_fingerprints, SPSync stops before it sends any credential, and there is no setting that turns the check off. Keep a second fingerprint in the list while you rotate the host key. SPSync ignores ~/.ssh/config, known_hosts and any SSH agent: it uses exactly what is configured here. The key, its passphrase and the password are never written to the config file or to the control store; they are stored as keychain or Key Vault references, and a plain environment variable name works for the CLI.

Test connection and spsync doctor open the same tunnel as a run and say so in their result: connected through SSH tunnel, then the user, host and port, and host key pinned. The read-only MCP server (spsync mcp serve) opens its own connection to the replica and does not go through the tunnel.

SPSync adds HostNameInCertificate= with the original host name, so the certificate check still runs against the real name. That keyword exists in ODBC Driver 18 for SQL Server only; with Driver 17 the check fails against the loopback address, so use Driver 18 for a tunnel.

Choose the mode on the Destination screen (Authentication) or in the destination.auth block of the config.

Mode (auth.mode) Use it when
integrated (preview, not run against a real domain controller) The SQL Server is domain-joined (on-premises, or Arc-enabled) and SPSync runs as a domain account. On Windows SPSync uses the signed-in Windows account. On macOS and Linux it uses a Kerberos ticket from kinit or a keytab.
password SQL authentication: a login and password in the connection string
Microsoft Entra modes, in preview and not verified live (entra_managed_identity, entra_service_principal_certificate, entra_default, entra_service_principal_secret) The instance supports Microsoft Entra authentication (SQL Server 2022 and later with Microsoft Entra enabled, including Arc-enabled instances). These behave as described for Azure SQL.

For integrated authentication leave the user and password out of the string:

mssql://HOST:1433/spsync?driver=ODBC+Driver+18+for+SQL+Server
destination:
kind: mssql
connection_string_env: SPSYNC_DSN
dataset_name: sync
auth:
mode: integrated

On macOS or Linux, get a ticket first with kinit <account>@<REALM>, or point the KRB5_CLIENT_KTNAME and KRB5CCNAME environment variables at a keytab and a ticket cache for unattended runs. The server needs a Service Principal Name registered for its host name. Amazon RDS for SQL Server and Google Cloud SQL for SQL Server are tested with password only.

The connection string has this shape, where HOST is your server’s name:

mssql://spsync_loader:PASSWORD@HOST:1433/spsync?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=yes
  • Desktop app: open the Destination screen, choose SQL Server / Azure SQL, paste the string into Connection string and choose Test connection. Table prefix is optional.

  • CLI: put the string in an environment variable and name the variable when you write the config:

    Terminal window
    export SPSYNC_DSN='mssql://spsync_loader:PASSWORD@HOST:1433/spsync?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=yes'
    spsync export-config --output replication.yaml \
    --site-url https://contoso.sharepoint.com/sites/x --list Projects \
    --pipeline-name spsync_dev --prefix dev \
    --destination-kind mssql --connection-string-env SPSYNC_DSN --dataset-name sync \
    --client-id <entra-app-client-id>

    --dataset-name is the schema you created above.

  • AI assistant: with the admin MCP server connected, ask the assistant for the destination requirements, then let it create the destination. You type the connection string into the secure entry page, never into the chat.

Both open a real connection with the string you gave and confirm the server accepts the login. That proves the host is reachable, the driver is installed, TLS negotiated and the password is right. It does not prove the login can create tables. A missing grant shows up on the first sync, as a permission error naming the object.

spsync doctor runs this check as destination-connectivity alongside its SharePoint checks.

What you see What it means and the fix
Can't open lib 'ODBC Driver 18 for SQL Server' The driver is not installed on the machine running SPSync. Install ODBC Driver 18, or change driver= to the version you have.
Login failed for user Wrong password, the login is disabled, or the server only allows Windows authentication. Turn on mixed mode, or use integrated.
Cannot generate SSPI context or No Kerberos credentials available integrated needs a Windows domain account, or on macOS and Linux a valid Kerberos ticket (klist) and a registered Service Principal Name for the server.
SSL Provider: certificate verify failed The server certificate is self-signed or from a CA the machine does not trust. Install the CA in the machine’s trust store (adding TrustServerCertificate=yes works but turns checking off).
TCP Provider: Timeout error or Named Pipes Provider A firewall or security group is blocking port 1433, or the host name is wrong.
The CREATE TABLE permission was denied The user is missing the grants above. Run the GRANT and CREATE SCHEMA ... AUTHORIZATION lines again.

If a connection fails with OpenSSL library could not be loaded, Homebrew’s openssl alias now points at OpenSSL 4, which Microsoft’s ODBC Driver 18 does not support. See Troubleshooting for the one-line fix.