# Installing ODBC Driver on Windows Server

## Quick Installation

### Method 1: Download and Install (Recommended)

1. **Download ODBC Driver 18:**
   - Direct: https://go.microsoft.com/fwlink/?linkid=2249004
   - File: `msodbcsql.msi`

2. **Run Installer:**
   ```powershell
   # As Administrator
   msiexec /i msodbcsql.msi
   ```

3. **Verify Installation:**
   ```powershell
   Get-OdbcDriver | Where-Object {$_.Name -like "*SQL Server*"}
   ```

Expected output:
```
Name                                 Version    Platform
----                                 -------    --------
ODBC Driver 18 for SQL Server        18.2.1.1   64-bit
```

### Method 2: Chocolatey (if installed)

```powershell
choco install sqlserver-odbcdriver18 -y
```

## Check What's Installed

```powershell
# List all SQL Server drivers
Get-OdbcDriver | Where-Object {$_.Name -like "*SQL*"}

# List driver details
(Get-OdbcDriver -Name "*SQL Server*").Properties
```

## Common Driver Names

- `ODBC Driver 18 for SQL Server` ✅ (Latest)
- `ODBC Driver 17 for SQL Server` ✅ (Compatible)
- `ODBC Driver 13 for SQL Server` ⚠️ (Older but works)
- `SQL Server Native Client 11.0` ⚠️ (Legacy)

**Note:** Update driver name in `aumentum_browser_service.py` if different.

## Connection String Test

```powershell
# Test connection works
$connString = "DRIVER={ODBC Driver 18 for SQL Server};SERVER=10.10.10.3,1433;DATABASE=LRS43;UID=sa;PWD=YOUR_PASSWORD;Encrypt=no;TrustServerCertificate=yes"
$conn = New-Object System.Data.Odbc.OdbcConnection($connString)
try {
    $conn.Open()
    Write-Host "Connection successful!" -ForegroundColor Green
    $conn.Close()
} catch {
    Write-Host "Connection failed: $_" -ForegroundColor Red
}
```

## Troubleshooting

### Driver Not Found

**Error:** `Can't open lib '{ ODBC Driver 18 for SQL Server }'`

**Fix:**
1. Verify exact driver name: `Get-OdbcDriver`
2. Check case sensitivity
3. Match name exactly in config file
4. Reinstall driver as Administrator

### Wrong Driver Architecture

**Error:** `architecture mismatch`

**Fix:**
1. Install correct version (64-bit vs 32-bit)
2. Match Python architecture: `python -c "import sys; print(sys.maxsize > 2**32)"`
3. Use 64-bit Python with 64-bit driver

### Connection Timeout

**Error:** `TCP Provider: Error code 0x2AF9`

**Fix:**
1. Verify SQL Server running: `netstat -an | findstr 1433`
2. Test network: `Test-NetConnection -ComputerName 10.10.10.3 -Port 1433`
3. Check firewall rules
4. Enable SQL Server authentication

## After Installation

Update config in `aumentum_browser_service.py`:

```python
DEFAULT_DB_CONFIG = {
    "backend": "mssql",
    "server": "10.10.10.3",
    "port": 1433,
    "database": "LRS43",
    "username": "sa",
    "password": "YOUR_ACTUAL_PASSWORD",  # Set this!
    "driver": "ODBC Driver 18 for SQL Server",  # Match installed driver
    "encrypt": "no",
    "trust_server_certificate": "yes",
}
```

Then test:
```powershell
python PLAGIS_AUMENTUM\test_db_connection.py
```

Expected success output:
```
🔌 Connecting to MSSQL: server=10.10.10.3:1433, database=LRS43...
✅ MSSQL connection successful to LRS43
✅ Found 100+ source documents
✅ Found 100+ matching content URLs
✅ Found 200+ tables
```

