---
title: SQL Server Connection Strings – Certificate Validation, AOAG, Authentication & Security
description: Complete guide to SQL Server connection strings in Nodinite. Learn about Microsoft.Data.SqlClient certificate validation, encryption settings, Always On Availability Groups, authentication methods, troubleshooting, and security best practices.
---

# :fa-link: SQL Server Connection Strings

A comprehensive guide to configuring SQL Server connection strings for :Nodinite: components. This page covers modern TLS certificate validation, [Always On Availability Groups][AOAGDocs], authentication methods, troubleshooting, and security best practices.

## :fa-circle-info: Overview

:Nodinite: [Core Services][] connect to the [Configuration Database][ConfigDB] with a connection string; the [Configuration Database][ConfigDB] then reaches the [Log Databases][] through [Linked Servers][], and some [Monitoring Agents][] use their own [Monitoring Database][Agent Database].

### Where You Set the Connection String in v7

For the Core Services, you set the connection string once per environment in the Nodinite Portal ([Step 3: Infrastructure][Portal SQL Server]), or pass it to the CLI at install or update time with `--database-connection-string` (see [Passing arguments when needed][Portal CLI Arguments]). The CLI writes it into each Core Service, and :Nodinite: protects it with [Secret Management][]. To change it later, for example after a [database migration][Moving Databases], change it in the Portal and run the [update][Updating Nodinite v7] again.

### Choose the Encryption Settings

<div class="mermaid">
flowchart TD
    Start["fa:fa-plug New or changed connection string"] --> Azure{"Azure SQL Managed Instance?"}
    Azure -->|"Yes"| AzureCfg["Encrypt=True<br/>TrustServerCertificate=False<br/>SQL authentication"]
    Azure -->|"No"| CA{"SQL Server certificate from a CA<br/>trusted by the Nodinite server?"}
    CA -->|"Yes"| Best["Encrypt=True<br/>TrustServerCertificate=False"]
    CA -->|"No, self-signed"| Pragmatic["Encrypt=True<br/>TrustServerCertificate=True"]
    Best --> AG{"Always On listener?"}
    Pragmatic --> AG
    AG -->|"Yes"| Multi["Add MultiSubnetFailover=True"]
    style AzureCfg fill:#2678BD
    style Best fill:#93d16d
    style Pragmatic fill:#FFD525
    style Multi fill:#3F827B
</div>

*Diagram: how to pick `Encrypt` and `TrustServerCertificate`. Green is the recommended production setting, yellow the pragmatic setting for self-signed certificates, and blue [Azure SQL Managed Instance](#fa-cloud-azure-sql-managed-instance). Add `MultiSubnetFailover=True` for an [Always On Availability Group][AlwaysOn] listener. The [Certificate Validation Decision Guide](#fa-shield-check-certificate-validation-decision-guide) below rates every option.*

### Why the Defaults Changed

:Nodinite: components connect to SQL Server databases using connection strings. Starting with **Microsoft.Data.SqlClient v4+**, default security settings have changed, requiring explicit configuration for certificate validation and encryption.

#### What Changed

|**Library Version**|**Default Behavior**|**Connection String Requirements**|  
|---|---|---|  
|**System.Data.SqlClient** (legacy)|`Encrypt=False` (no TLS)<br>`TrustServerCertificate=True` (accept any cert)|✅ Encryption parameters **optional**<br>❌ Old connection strings often have **no Encrypt/TrustServerCertificate parameters at all**|  
|**Microsoft.Data.SqlClient v4+** (modern)|`Encrypt=True` (TLS required)<br>`TrustServerCertificate=False` (validate cert chain)|⚠️ Encryption parameters **now mandatory**<br>✅ Must explicitly add `Encrypt=True;TrustServerCertificate=True/False`|  

#### Impact

* **Upgrading from System.Data.SqlClient:** Old connection strings without `Encrypt` or `TrustServerCertificate` parameters will cause "The certificate chain was issued by an authority that is not trusted" errors
* **Upgrading :Nodinite: components:** If SQL Server uses self-signed certificates, you must add encryption parameters to existing connection strings

>[!IMPORTANT]
>All connection strings stored in :Nodinite: are encrypted using certificate-based encryption. See the [Secret Management][] guide for details on how :Nodinite: securely stores passwords, connection strings, and other sensitive data using automated certificate handling.

## :fa-code: Common Connection String Examples

### Basic Connection (Self-Signed Certificate)

```ini
Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;
```

**Use when:** Dev/test environments with self-signed certificates

### Production Connection (Trusted CA)

```ini
Data Source=SQL01\INSTANCE;Initial Catalog=DatabaseName;Integrated Security=True;Encrypt=True;TrustServerCertificate=False;
```

**Use when:** Production with properly configured SQL Server certificates from trusted CA

### SQL Authentication

```ini
Data Source=sql.contoso.com,1433;Initial Catalog=DatabaseName;User ID=nodinite_user;Password=***;Encrypt=True;TrustServerCertificate=True;
```

**Use when:** Windows Authentication not available (not recommended for production)

## :fa-gear: Connection String Settings

|**Setting**|**Purpose**|**Values**|**Default (v4+)**|  
|---|---|---|---|  
|**Data Source**|SQL Server instance name or IP|`localhost`, `SQL01`, `SQL01\INSTANCE`, `192.168.1.10,1433`|*Required*|  
|**Initial Catalog**|Database name|Database name|*Required*|  
|**Integrated Security**|Windows authentication|`True` (recommended), `False`|`False`|  
|**User ID / Password**|SQL Server authentication|Username and password|*(none)*|  
|**Encrypt**|TLS encryption on/off|`True` (recommended), `False`, `Mandatory`, `Strict`|`True`|  
|**TrustServerCertificate**|Skip certificate validation|`True` (self-signed), `False` (validate CA)|`False`|  
|**MultiSubnetFailover**|Always On AG fast failover|`True` (AG), `False` (standalone)|`False`|  
|**ApplicationIntent**|Read-only routing|`ReadWrite` (default), `ReadOnly`|`ReadWrite`|  
|**Connect Timeout**|Connection timeout (seconds)|`15`, `30` (default), `60`|`30`|  
|**Pooling**|Connection pooling|`True` (default), `False`|`True`|  
|**Min Pool Size / Max Pool Size**|Pool limits|`0` / `100` (defaults)|`0` / `100`|  

See the [complete connection string reference][ConnectionStrings]<sup>:fa-arrow-up-right-from-square:</sup>.

## :fa-shield-check: Certificate Validation Decision Guide

Choose the right certificate configuration for your environment:

|**Scenario**|**Encrypt**|**TrustServerCertificate**|**Security Level**|**Use Case**|  
|---|---|---|---|---|  
|**Production with trusted CA**|`True`|`False`|✅✅✅ Highest|SQL Server cert from public/enterprise CA, cert chain trusted by OS|  
|**Production with self-signed**|`True`|`True`|✅✅ Medium|SQL Server uses self-signed cert, pragmatic security|  
|**Dev/Test**|`True`|`True`|✅✅ Medium|Development environments, quick setup|  
|**Legacy (not recommended)**|`False`|*N/A*|❌ Low|Old applications, testing only|  
|**Strict mode (SQL 2022+)**|`Strict`|`False`|✅✅✅✅ Highest|Maximum security with TDS 8.0|  

>[!IMPORTANT]
>**After upgrading :Nodinite: components or migrating from System.Data.SqlClient**, if you see certificate errors:
>
>1. **Check your connection strings:** Old connection strings may be **missing `Encrypt` and `TrustServerCertificate` parameters entirely** - see [Migrating from System.Data.SqlClient](#fa-circle-info-overview)
>2. **Best practice:** Install SQL Server certificate's issuing CA on the :Nodinite: host, then use `Encrypt=True;TrustServerCertificate=False`
>3. **Quick fix:** Add `Encrypt=True;TrustServerCertificate=True` to connection strings (accepts self-signed certificates)
>4. **Not recommended:** Set `Encrypt=False` (testing environments only - sends data unencrypted)

## :fa-cloud: Azure SQL Managed Instance

Azure SQL Managed Instance is a fully managed SQL Server platform-as-a-service (PaaS) in Azure. It requires SQL authentication and always uses encrypted connections.

### Basic Azure SQL Managed Instance Connection

```ini
Server=tcp:myinstance.database.windows.net,1433;Initial Catalog=DatabaseName;User ID=sqladmin;Password=***;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
```

**Use when:** Hosting :Nodinite: databases in Azure SQL Managed Instance

### Recommended Azure SQL Managed Instance Settings

|**Setting**|**Value**|**Why**|  
|---|---|---|  
|**Server**|`tcp:yourinstance.database.windows.net,1433`|Azure SQL Managed Instance FQDN|  
|**User ID / Password**|SQL authentication credentials|Windows authentication not supported|  
|**Encrypt**|`True`|**Required** — Azure SQL enforces encryption|  
|**TrustServerCertificate**|`False`|Azure uses trusted CA certificates|  
|**Connection Timeout**|`30` or higher|Account for network latency to Azure|  
|**Persist Security Info**|`False` (default)|Security best practice|  
|**MultipleActiveResultSets**|`False` (default)|Use `True` if needed by application|  

### Full Example with Best Practices

```ini
Server=tcp:nodinite-prod.database.windows.net,1433;Initial Catalog=Nodinite_Prod_Config;Persist Security Info=False;User ID=nodinite_admin;Password=ComplexP@ssw0rd!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
```

### Azure SQL Database vs Managed Instance

|**Feature**|[Azure SQL Database][Azure SQL Database]|**Azure SQL Managed Instance**|  
|---|---|---|  
|:Nodinite: [Core Services][] support|❌ Not supported|✅ Supported (>=6.1)|  
|**Connection String**|Similar format|`tcp:instance.database.windows.net`|  
|**Authentication**|SQL auth only|SQL auth only|  
|**Encryption**|Always encrypted|Always encrypted|  
|**Compatibility**|Limited T-SQL|Near 100% SQL Server compatibility|  
|[Linked Servers][]|Not supported|✅ Supported|  
|**SQL Agent**|Not available|✅ Available|  

>[!IMPORTANT]
>**:Nodinite: requires Azure SQL Managed Instance**, not Azure SQL Database. Managed Instance provides the SQL Server features :Nodinite: depends on (linked servers, SQL Agent, full T-SQL compatibility).

### Azure SQL Managed Instance Checklist

* ✅ Use **Azure SQL Managed Instance**, not Azure SQL Database
* ✅ Create SQL login with appropriate permissions
* ✅ Set `Encrypt=True` (enforced by Azure)
* ✅ Keep `TrustServerCertificate=False` (Azure uses trusted certificates)
* ✅ Configure Azure firewall to allow :Nodinite: server's IP address
* ✅ Consider using private endpoint for secure connectivity
* ✅ Increase `Connection Timeout=60` if experiencing network latency
* ✅ Store passwords in secure secret management (Azure Key Vault, etc.)

### Common Azure SQL Issues

|**Symptom**|**Cause**|**Solution**|  
|---|---|---|  
|"Cannot open server"|Firewall blocking connection|Add client IP to Azure SQL firewall rules|  
|"Login failed for user"|Invalid credentials|Verify username/password, check SQL login exists|  
|Connection timeout|Network latency to Azure|Increase `Connection Timeout=60` or higher|  
|"Server was not found"|Incorrect server name|Verify FQDN format: `tcp:instance.database.windows.net,1433`|  

## :fa-sync-alt: Always On Availability Groups (AOAG)

### Why Use AOAG?

**Always On Availability Groups** provide high availability and disaster recovery for SQL Server databases. When :Nodinite: connects to AOAG, the **AG listener** handles automatic failover—ensuring minimal downtime during SQL Server maintenance or failures.

### Minimum AOAG Connection String

```ini
Data Source=AG-Listener;Initial Catalog=DatabaseName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;
```

**This works**, but reconnection after failover may take 10-20 seconds.

### Recommended AOAG Connection String

```ini
Data Source=AG-Listener;Initial Catalog=DatabaseName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;MultiSubnetFailover=True;
```

**Optimized for fast failover** (2-3 seconds vs 10-20 seconds).

### Key AOAG Settings

|**Setting**|**Required?**|**Purpose**|**Impact if Missing**|  
|---|---|---|---|  
|**Data Source** (listener)|✅ Required|Connect via AG listener, not individual nodes|Connection fails or points to wrong replica after failover|  
|**MultiSubnetFailover=True**|⚡ Recommended|Parallel connection attempts for faster failover|Slower reconnection (10-20s vs 2-3s)|  
|**ApplicationIntent**|Optional|`ReadWrite` ensures writes go to primary|Rare: may route to read-only secondary|  
|**Connect Timeout**|Optional|Increase to 60s if slow failovers|Connection may timeout during failover|  

### When is `MultiSubnetFailover=True` Critical?

* **Multi-subnet deployments** (different datacenters/availability zones) — **Critical** for acceptable failover times
* **Single-subnet deployments** — **Helpful** but not required; reduces failover from ~15s to ~3s
* **Production workloads** — **Recommended**; improves perceived reliability during maintenance

### AOAG Deployment Checklist

* ✅ Use the **AG listener name** as Data Source—never individual SQL Server names (**Required**)
* ✅ Verify database is in the AG and synchronized (**Required**)
* ⚡ Add `MultiSubnetFailover=True` for faster failover (**Recommended** for multi-subnet)
* ⚡ Test failover: stop primary replica, verify automatic reconnection
* ⚡ Increase `Connect Timeout=60` if intermittent timeout errors during failover
* ⚡ Configure AG listener with static IP addresses for predictable DNS resolution

### Common AOAG Issues

|**Symptom**|**Cause**|**Solution**|  
|---|---|---|  
|Slow reconnection (10-20 seconds)|Missing `MultiSubnetFailover=True`|Add `MultiSubnetFailover=True`|  
|"Login failed for user" after failover|SQL logins not synchronized|Use Windows auth OR sync logins to all replicas|  
|Timeout errors during failover|Default timeout too short|Increase `Connect Timeout=60`|  
|Connects to read-only secondary|Incorrect routing configuration|Add `ApplicationIntent=ReadWrite`|  
|Connection hangs (multi-subnet)|Sequential IP attempts with timeouts|Add `MultiSubnetFailover=True` (**critical**)|  

>[!TIP]
>Always test AG failover in non-production first. Monitor reconnection behavior and verify components resume automatically after the new primary replica is online.

## :fa-triangle-exclamation: Troubleshooting Certificate Errors

### "The certificate chain was issued by an authority that is not trusted"

**Cause:** SQL Server uses a self-signed certificate or certificate from untrusted CA

#### Solutions

1. **Best practice (Production):**
   * Export SQL Server certificate's root CA certificate
   * Install on :Nodinite: host's Trusted Root Certification Authorities store
   * Keep `Encrypt=True;TrustServerCertificate=False` in connection string

2. **Pragmatic (Dev/Test):**
   * Add `TrustServerCertificate=True` to connection string
   * Keeps encryption but bypasses certificate validation

3. **Not recommended:**
   * Set `Encrypt=False` in connection string
   * Disables TLS encryption entirely

### "The target principal name is incorrect"

**Cause:** Certificate CN/SAN doesn't match the Data Source name

#### Solutions

* Use DNS name from certificate in `Data Source` setting
* OR update SQL Server certificate with correct SAN entries
* OR add `TrustServerCertificate=True` (bypasses name check)

### TLS Handshake Failures

**Cause:** TLS protocol version mismatch

#### Solutions

* Enable TLS 1.2+ in Windows (via registry)
* Enable TLS 1.2+ in SQL Server configuration
* Update .NET Framework to support modern TLS

### Connection Timeout During Failover (AOAG)

**Cause:** Default 30-second timeout too short for AG failover

#### Solution

* Add `Connect Timeout=60` to connection string
* Verify `MultiSubnetFailover=True` is present

### Password with Special Characters

**Cause:** Passwords containing special characters like `;` (semicolon) are misinterpreted as connection string delimiters

#### Solutions

1. **Best practice (All environments):**
   * Use **Windows Authentication** (`Integrated Security=True`) to avoid passwords in connection strings entirely
   * See [Secret Management][] for secure credential storage

2. **If SQL Authentication required:**
   * **Escape the password** by enclosing it in **single quotes**:

   ```ini
   Data Source=localhost;Initial Catalog=MSDB;User ID=ServiceAccountName;Password='Da;Password';
   ```

   * Characters that require escaping: `;` `=` `'` (any delimiter used in connection strings)

3. **Not recommended:**
   * Avoid passwords with special characters (limits password complexity)

#### Example

❌ **Incorrect** (password interpreted as multiple parameters):

```ini
Server=localhost;Database=MSDB;User Id=ServiceAccountName;Password=Da;Password;
```

✅ **Correct** (password enclosed in single quotes):

```ini
Server=localhost;Database=MSDB;User Id=ServiceAccountName;Password='Da;Password';
```

>[!TIP]
>For passwords with single quotes, escape with double single quotes: `Password='O''Brien'` for password `O'Brien`

## :fa-lock: Security Best Practices

### :fa-circle-check: Do This

* **Use `Encrypt=True` everywhere** — Encrypts all data in transit
* **Prefer `TrustServerCertificate=False` with proper CA trust** — Validates certificate chain
* **Use Windows Authentication** (`Integrated Security=True`) — No passwords in connection strings
* **For AOAG, use listener name and `MultiSubnetFailover=True`** — Ensures fast failover
* **Use least-privilege SQL accounts** — Grant only necessary permissions
* **Rotate SQL passwords regularly** — If SQL auth is required
* **Enable SSL/TLS 1.2+** — Disable older protocols

### :fa-circle-xmark: Avoid This

* **`Encrypt=False` in production** — Sends data unencrypted over network
* **Embedding passwords in connection strings** — Use Windows auth or secure secret storage
* **SQL Authentication without encryption** — Passwords sent in cleartext if `Encrypt=False`
* **Self-signed certificates in production without documentation** — Creates security debt
* **Individual SQL Server names with AOAG** — Breaks automatic failover

### Connection String Security Levels

|**Configuration**|**Security Rating**|**Production Ready?**|  
|---|---|---|  
|`Encrypt=True;TrustServerCertificate=False` + trusted CA|✅✅✅✅ Excellent|✅ Yes|  
|`Encrypt=True;TrustServerCertificate=True` + Windows auth|✅✅✅ Good|✅ Yes (pragmatic)|  
|`Encrypt=True;TrustServerCertificate=True` + SQL auth|✅✅ Fair|⚠️ Use with caution|  
|`Encrypt=False` + Windows auth|✅ Poor|❌ Dev/test only|  
|`Encrypt=False` + SQL auth|❌ Very Poor|❌ Never use|  

## :fa-book: External References

* [Microsoft.Data.SqlClient documentation][SqlClientDocs]<sup>:fa-arrow-up-right-from-square:</sup>
* [Connection string syntax][ConnectionStrings]<sup>:fa-arrow-up-right-from-square:</sup>
* [SQL Server Always On Availability Groups][AOAGDocs]<sup>:fa-arrow-up-right-from-square:</sup>
* [MultiSubnetFailover keyword][MultiSubnetDocs]<sup>:fa-arrow-up-right-from-square:</sup>
* [SQL Server TLS/SSL configuration][TLSDocs]<sup>:fa-arrow-up-right-from-square:</sup>

## :fa-hand-point-right: Next Steps

* :fa-shield-check: [SQL Server Firewall Configuration][SQL Firewall]  
* :fa-server: [Always On Availability Groups][AlwaysOn]  
* :fa-key: [Secret Management][]  
* :fa-forward-step: [Step 3: Infrastructure][Portal SQL Server]  

## :fa-link-horizontal: Related Topics

* :fa-database: [SQL Server Troubleshooting][SQL Server Overview]  
* :fa-database: [Agent Database][Agent Database]  
* :fa-truck-moving: [Moving Databases][]  
* :fa-database: [SQL Server Options][Microsoft SQL Server]  
* :fa-link: [Linked Servers][]  
* :fa-arrow-turn-up: [Updating Nodinite v7][]  

[Agent Database]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/Agent%20Database.md
[AlwaysOn]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/Always%20On%20Availability%20Groups.md
[AOAGDocs]:https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server
[Azure SQL Database]:{ndr}/Logging%20and%20Monitoring/Database/Features/Azure%20SQL%20Database/Overview.md
[ConfigDB]:{ndr}/Core%20Services/Configuration%20Database/Overview.md
[ConnectionStrings]:https://www.connectionstrings.com/sql-server/
[Core Services]:{ndr}/Core%20Services/Overview.md
[Linked Servers]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/Linked%20Servers.md
[Log Databases]:{ndr}/Core%20Services/Log%20Databases/Overview.md
[Microsoft SQL Server]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/SQL%20Server%20Options.md
[Monitoring Agents]:{ndr}/Administration/2.%20Monitor%20Management/2.%20Monitor%20Agents/Features/What%20is%20a%20Monitor%20Agent.md
[Moving Databases]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/Database%20Migration/Overview.md
[MultiSubnetDocs]:https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring
[Portal CLI Arguments]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/07%20-%20Install%20the%20Generated%20Package.md#passing-arguments-when-needed
[Portal SQL Server]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/03%20-%20Infrastructure.md#configure-sql-server-connectivity
[Secret Management]:{ndr}/Install%20and%20Update/Troubleshooting/Secret%20Managment.md
[SQL Firewall]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/Firewall.md
[SQL Server Overview]:{ndr}/Install%20and%20Update/Troubleshooting/SQL%20Server/Overview.md
[SqlClientDocs]:https://learn.microsoft.com/en-us/sql/connect/ado-net/introduction-microsoft-data-sqlclient-namespace
[TLSDocs]:https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-sql-server-encryption
[Updating Nodinite v7]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Updating%20Nodinite%20v7.md