Skip to content

Commit 5a18e93

Browse files
vkuttypCopilot
andcommitted
docs: update README and ConnectingToSQLServer for v1.1.0 features
- Add TrustServerCertificate, connection string parsing, checkReachability to features table - Add Swift 6 strict concurrency row to features table - Expand Quick Start with connection string example - Rewrite TLS/SSL section with TrustServerCertificate and checkReachability examples - Fully rewrite ConnectingToSQLServer.md with new API surface - Replace aBCD111 → SuperStr0ngP@ssword everywhere in docs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 13c4908 commit 5a18e93

5 files changed

Lines changed: 133 additions & 41 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ jobs:
9595
image: mcr.microsoft.com/mssql/server:2022-latest
9696
env:
9797
ACCEPT_EULA: "Y"
98-
SA_PASSWORD: "aBCD111!"
98+
SA_PASSWORD: "SuperStr0ngP@ssword!"
9999
MSSQL_PID: Developer
100100
ports: ["1433:1433"]
101101
options: >-
102-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'aBCD111!' -Q 'SELECT 1' -C"
102+
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'SuperStr0ngP@ssword!' -Q 'SELECT 1' -C"
103103
--health-interval 10s
104104
--health-retries 15
105105
steps:
@@ -111,14 +111,14 @@ jobs:
111111
run: sudo apt-get install -y libsqlite3-dev
112112
- name: Create test database
113113
run: |
114-
until /opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'aBCD111!' -C \
114+
until /opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'SuperStr0ngP@ssword!' -C \
115115
-Q "CREATE DATABASE MSSQLNioTestDb" 2>/dev/null; do
116116
echo "Waiting for SQL Server..."; sleep 3
117117
done
118118
- name: Run MSSQL tests
119119
env:
120120
MSSQL_TEST_HOST: "127.0.0.1"
121-
MSSQL_TEST_PASS: "aBCD111!"
121+
MSSQL_TEST_PASS: "SuperStr0ngP@ssword!"
122122
MSSQL_TEST_DB: MSSQLNioTestDb
123123
MSSQL_TEST_USER: sa
124124
run: swift test --filter MSSQLNioTests

README.md

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ A unified Swift package for connecting to **Microsoft SQL Server**, **PostgreSQL
4848
|---|:---:|:---:|:---:|:---:|
4949
| Native wire protocol | TDS 7.4 | v3 | v10 | sqlite3 |
5050
| TLS / SSL encryption |||| N/A |
51+
| TrustServerCertificate |||||
52+
| Connection string parsing |||||
53+
| `checkReachability()` |||||
54+
| Swift 6 strict concurrency |||||
5155
| Unified `SQLDatabase` protocol |||||
5256
| `async/await` API |||||
5357
| Parameterized queries |||||
@@ -118,12 +122,21 @@ You can import only the drivers you need — each is an independent library modu
118122
```swift
119123
import MSSQLNio
120124

125+
// Programmatic configuration
121126
let config = MSSQLConnection.Configuration(
122-
host: "localhost",
123-
port: 1433, // default
124-
database: "AdventureWorks",
125-
username: "sa",
126-
password: "YourPassword!"
127+
host: "localhost",
128+
port: 1433,
129+
database: "AdventureWorks",
130+
username: "sa",
131+
password: "YourPassword!",
132+
trustServerCertificate: true // set true for self-signed certs (dev/test)
133+
)
134+
135+
// Or from a connection string
136+
let config = try MSSQLConnection.Configuration(connectionString:
137+
"Server=localhost,1433;Database=AdventureWorks;" +
138+
"User Id=sa;Password=YourPassword!;" +
139+
"Encrypt=True;TrustServerCertificate=True;"
127140
)
128141

129142
let conn = try await MSSQLConnection.connect(configuration: config)
@@ -696,14 +709,34 @@ config.tls = .prefer
696709
config.tls = .disable
697710
```
698711

699-
For development/testing with self-signed certificates, disable certificate verification:
712+
### TrustServerCertificate (SQL Server)
713+
714+
Self-signed certificates (Docker, local dev) require bypassing certificate verification:
715+
716+
```swift
717+
// Via init:
718+
let config = MSSQLConnection.Configuration(
719+
host: "localhost", database: "MyDb",
720+
username: "sa", password: "pass",
721+
trustServerCertificate: true
722+
)
723+
724+
// Via connection string:
725+
let config = try MSSQLConnection.Configuration(connectionString:
726+
"Server=localhost;Database=MyDb;User Id=sa;Password=pass;" +
727+
"Encrypt=True;TrustServerCertificate=True;"
728+
)
729+
```
730+
731+
> **Warning:** `trustServerCertificate: true` disables certificate validation. Use only in development/testing, never in production.
732+
733+
### Reachability check (SQL Server)
700734

701-
> **Warning:** Never use in production.
735+
Perform a fast TCP pre-flight before a full TDS connection attempt:
702736

703737
```swift
704-
// MSSQL
705-
var config = MSSQLConnection.Configuration(...)
706-
config.tls = .prefer // MSSQL defaults to TLS-first via pre-login negotiation
738+
try await config.checkReachability() // throws if host:port unreachable
739+
let conn = try await MSSQLConnection.connect(configuration: config)
707740
```
708741

709742
---
@@ -930,12 +963,12 @@ swift test --filter SQLiteNioTests
930963
# Start SQL Server in Docker
931964
docker run -d --name sqlserver \
932965
-e ACCEPT_EULA=Y \
933-
-e SA_PASSWORD=aBCD111 \
966+
-e SA_PASSWORD=SuperStr0ngP@ssword \
934967
-p 1433:1433 \
935968
mcr.microsoft.com/mssql/server:2022-latest
936969

937970
# Run tests
938-
MSSQL_TEST_HOST=127.0.0.1 MSSQL_TEST_PASS=aBCD111 swift test --filter MSSQLNioTests
971+
MSSQL_TEST_HOST=127.0.0.1 MSSQL_TEST_PASS=SuperStr0ngP@ssword swift test --filter MSSQLNioTests
939972
```
940973

941974
### PostgreSQL
@@ -970,7 +1003,7 @@ MYSQL_TEST_HOST=127.0.0.1 swift test --filter MySQLNioTests
9701003
swift test --filter SQLiteNioTests
9711004

9721005
# Run all integration tests (requires all three containers above)
973-
MSSQL_TEST_HOST=127.0.0.1 MSSQL_TEST_PASS=aBCD111 \
1006+
MSSQL_TEST_HOST=127.0.0.1 MSSQL_TEST_PASS=SuperStr0ngP@ssword \
9741007
PG_TEST_HOST=127.0.0.1 \
9751008
MYSQL_TEST_HOST=127.0.0.1 \
9761009
swift test

Sources/MSSQLNio/Documentation.docc/Articles/ConnectingToSQLServer.md

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,109 @@ Configure and establish connections to Microsoft SQL Server.
88

99
## Configuration
1010

11+
### Programmatic configuration
12+
1113
```swift
1214
import MSSQLNio
1315

1416
var config = MSSQLConnection.Configuration(
15-
host: "sqlserver.example.com",
16-
port: 1433, // default
17-
database: "AdventureWorks",
18-
username: "sa",
19-
password: "YourStrongPassword!"
17+
host: "sqlserver.example.com",
18+
port: 1433, // default
19+
database: "AdventureWorks",
20+
username: "sa",
21+
password: "YourStrongPassword!",
22+
trustServerCertificate: false // true = skip cert verification
2023
)
2124

2225
// Optional settings
23-
config.tls = .prefer // .require / .prefer / .disable
24-
config.connectTimeout = 30 // seconds (default: 30)
25-
config.queryTimeout = nil // per-query timeout in seconds (nil = no limit)
26-
config.readOnly = false // mark connection as read-only hint
26+
config.tls = .prefer // .require / .prefer / .disable
27+
config.connectTimeout = 30 // seconds (default: 30)
28+
config.queryTimeout = nil // per-query timeout (nil = no limit)
29+
config.readOnly = false // read-only hint for AG replicas
2730

2831
let conn = try await MSSQLConnection.connect(configuration: config)
2932
defer { Task { try? await conn.close() } }
3033
```
3134

35+
### Connection string
36+
37+
You can also initialise directly from a standard SQL Server connection string:
38+
39+
```swift
40+
let config = try MSSQLConnection.Configuration(connectionString:
41+
"Server=sqlserver.example.com,1433;Database=AdventureWorks;" +
42+
"User Id=sa;Password=YourStrongPassword!;" +
43+
"Encrypt=True;TrustServerCertificate=False;Connect Timeout=30;"
44+
)
45+
let conn = try await MSSQLConnection.connect(configuration: config)
46+
```
47+
48+
Supported keys (case-insensitive):
49+
50+
| Key | Aliases | Values |
51+
|-----|---------|--------|
52+
| `Server` | `Data Source` | `host` or `host,port` |
53+
| `Database` | `Initial Catalog` | database name |
54+
| `User Id` | `UID` | username |
55+
| `Password` | `PWD` | password |
56+
| `Domain` || enables NTLM/Windows auth |
57+
| `Encrypt` || `True`/`False`/`Disable`/`Strict`/`Request` |
58+
| `TrustServerCertificate` || `True` skips cert verification |
59+
| `Connect Timeout` | `Connection Timeout` | seconds |
60+
| `Application Intent` || `ReadOnly` |
61+
62+
## TLS and TrustServerCertificate
63+
64+
Self-signed certificates (common in dev/test environments including Docker) require `TrustServerCertificate=True`:
65+
66+
```swift
67+
// Via init:
68+
let config = MSSQLConnection.Configuration(
69+
host: "127.0.0.1", database: "MyDb",
70+
username: "sa", password: "pass",
71+
trustServerCertificate: true // skip cert verification for self-signed certs
72+
)
73+
74+
// Via connection string:
75+
let config = try MSSQLConnection.Configuration(connectionString:
76+
"Server=127.0.0.1;Database=MyDb;User Id=sa;Password=pass;" +
77+
"Encrypt=True;TrustServerCertificate=True;"
78+
)
79+
```
80+
81+
## Reachability Check
82+
83+
Perform a fast TCP-level pre-flight check before attempting a full TDS connection:
84+
85+
```swift
86+
// On Configuration (recommended):
87+
try await config.checkReachability() // throws SQLError.connectionError if unreachable
88+
let conn = try await MSSQLConnection.connect(configuration: config)
89+
90+
// Static version with explicit host/port:
91+
try await MSSQLConnection.checkReachability(host: "sqlserver.example.com", port: 1433, timeout: 5)
92+
```
93+
3294
## Azure SQL Database
3395

34-
Azure SQL uses the same TDS protocol. Append the server suffix to the host name and ensure TLS is enabled:
96+
Azure SQL uses the same TDS protocol. Append the server suffix to the host and require TLS:
3597

3698
```swift
37-
var config = MSSQLConnection.Configuration(
38-
host: "myserver.database.windows.net",
39-
database: "mydb",
40-
username: "myuser@myserver",
41-
password: "AzurePassword!"
99+
let config = try MSSQLConnection.Configuration(connectionString:
100+
"Server=myserver.database.windows.net;Database=mydb;" +
101+
"User Id=myuser@myserver;Password=AzurePassword!;" +
102+
"Encrypt=True;TrustServerCertificate=False;"
42103
)
43-
config.tls = .require // Azure requires TLS
44104
```
45105

46106
## Named Instances
47107

48108
SQL Server named instances listen on a dynamic port. Resolve the port first (via SQL Server Browser on UDP 1434), then connect directly:
49109

50110
```swift
51-
// After resolving the named instance port:
52111
let config = MSSQLConnection.Configuration(
53-
host: "sqlserver.example.com",
54-
port: 52108, // resolved instance port
112+
host: "sqlserver.example.com",
113+
port: 52108, // resolved instance port
55114
database: "MyDb",
56115
username: "sa",
57116
password: "pass"
@@ -68,10 +127,10 @@ let conn = try await MSSQLConnection.connect(configuration: config)
68127
// Using defer (recommended for scoped use):
69128
defer { Task { try? await conn.close() } }
70129

71-
// Or explicit close at the end of a Task:
130+
// Or explicit close:
72131
try await conn.close()
73132

74-
// Check if still open
133+
// Check if still open:
75134
if conn.isOpen {
76135
let rows = try await conn.query("SELECT GETDATE() AS now")
77136
}

Tests/MSSQLNioTests/SQLClientCompatTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// Environment variables (same as the rest of the test suite):
77
// MSSQL_TEST_HOST=127.0.0.1
8-
// MSSQL_TEST_PASS=aBCD111
8+
// MSSQL_TEST_PASS=SuperStr0ngP@ssword
99
// swift test --filter SQLClientCompat
1010

1111
import XCTest

Tests/MSSQLNioTests/Support/TestDatabase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import MSSQLNio
99
// MSSQL_TEST_HOST=127.0.0.1 \
1010
// MSSQL_TEST_PORT=1433 \
1111
// MSSQL_TEST_USER=sa \
12-
// MSSQL_TEST_PASS=aBCD111 \
12+
// MSSQL_TEST_PASS=SuperStr0ngP@ssword \
1313
// MSSQL_TEST_DB=MSSQLNioTestDb \
1414
// swift test --filter MSSQLNio
1515
//
@@ -28,7 +28,7 @@ struct TestDatabase {
2828
port: Int(env["MSSQL_TEST_PORT"] ?? "1433") ?? 1433,
2929
database: env["MSSQL_TEST_DB"] ?? "MSSQLNioTestDb",
3030
username: env["MSSQL_TEST_USER"] ?? "sa",
31-
password: env["MSSQL_TEST_PASS"] ?? "aBCD111",
31+
password: env["MSSQL_TEST_PASS"] ?? "SuperStr0ngP@ssword",
3232
trustServerCertificate: true
3333
)
3434
}

0 commit comments

Comments
 (0)