====== Runbook: Gestire DSN ======
**Durata:** ~10 minuti \\
**Ruolo:** Operatore Gateway \\
**Prerequisito:** Accesso a appsettings.json
DSN (Data Source Name) definisce connessioni database preconfigurate.
----
===== Workflow =====
flowchart TD
A[Richiesta DSN] --> B{Nuova o esistente?}
B -->|Nuova| C[Modificare appsettings.json]
B -->|Esistente| D[Testare connessione]
C --> E[Riavviare Gateway]
E --> D
D --> F{Test riuscito?}
F -->|Si| G[Documentare]
F -->|No| H[Verificare Connection String]
H --> C
style G fill:#e8f5e9
style H fill:#ffebee
----
===== 1. Visualizzare DSN esistenti =====
# Elencare tutti i DSN configurati (API)
curl -s http://localhost:5000/api/v1/dsn | jq
# Oppure controllare direttamente in Config
cat appsettings.json | jq '.Gateway.Databases'
----
===== 2. Aggiungere nuovo DSN =====
**Modificare appsettings.json:**
{
"Gateway": {
"Databases": {
"demo": {
"Provider": "sqlite",
"ConnectionString": "Data Source=data/demo.db"
},
"produzione": {
"Provider": "sqlserver",
"ConnectionString": "Server=sql01;Database=ProdDB;User Id=app;Password=***;TrustServerCertificate=True"
},
"reporting": {
"Provider": "postgresql",
"ConnectionString": "Host=pg01;Database=reports;Username=reader;Password=***"
}
}
}
}
**Provider supportati:**
| Provider | Esempio ConnectionString |
|----------|---------------------------|
| ''sqlserver'' | ''Server=host;Database=db;User Id=user;Password=pwd'' |
| ''sqlite'' | ''Data Source=path/file.db'' |
| ''postgresql'' | ''Host=host;Database=db;Username=user;Password=pwd'' |
| ''mysql'' | ''Server=host;Database=db;User=user;Password=pwd'' |
----
===== 3. Riavviare Gateway =====
# Windows
Stop-Process -Name "WvdS.WebAPI.Data.Gateway.Api" -Force
Start-Process -FilePath ".\WvdS.WebAPI.Data.Gateway.Api.exe"
# Linux (systemd)
sudo systemctl restart data-gateway
----
===== 4. Testare DSN =====
# Elencare tabelle del nuovo DSN
curl -s http://localhost:5000/api/v1/dsn/produzione/tables | jq
# Recuperare primi dati
curl -s "http://localhost:5000/api/v1/dsn/produzione/tables/Customers?\$top=5" | jq
----
===== 5. Rimuovere DSN =====
- Eliminare voce DSN da ''appsettings.json''
- Riavviare Gateway
- Verificare che DSN non sia piu disponibile:
curl -s http://localhost:5000/api/v1/dsn/vecchio_dsn/tables
# Risposta attesa: 404 Not Found
----
===== Checklist =====
| # | Punto di verifica | v |
|---|-----------|---|
| 1 | Provider corretto (sqlserver/sqlite/...) | ☐ |
| 2 | Connection String valido | ☐ |
| 3 | Password non visibile nei log | ☐ |
| 4 | Gateway riavviato | ☐ |
| 5 | Test API riuscito | ☐ |
----
===== Troubleshooting =====
| Problema | Causa | Soluzione |
|---------|---------|--------|
| ''Database not found'' | Database errato | Verificare nome database |
| ''Login failed'' | Password errata | Verificare credenziali |
| ''Connection refused'' | Firewall blocca | Aprire porta 1433/5432/3306 |
| ''Provider not supported'' | Nome provider errato | sqlserver, sqlite, postgresql, mysql |
| ''JSON parse error'' | Errore sintassi | Validare JSON (jsonlint.com) |
----
===== Note sulla Sicurezza =====
**Non loggare mai password in chiaro!**
Usare variabili ambiente per le credenziali:
"ConnectionString": "Server=sql01;Database=ProdDB;User Id=${DB_USER};Password=${DB_PASS}"
----
===== Runbook Correlati =====
* [[.:server-starten|Avviare server]] - Dopo modifica Config
* [[.:health-check|Health Check]] - Verificare connessione
* [[..:..:administrator:konfiguration:datenbanken|Configurazione Database]] - Riferimento dettagliato
----
<< [[.:server-starten|<- Avviare server]] | [[.:health-check|-> Health Check]] >>
----
//Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional//
{{tag>operator runbook dsn database configurazione}}