Durata: ~10 minuti
Ruolo: Operatore Gateway
Prerequisito: Accesso a appsettings.json
DSN (Data Source Name) definisce connessioni database preconfigurate.
# 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'
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 |
# 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
# 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
appsettings.jsoncurl -s http://localhost:5000/api/v1/dsn/vecchio_dsn/tables # Risposta attesa: 404 Not Found
| # | 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 | ☐ |
| 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) |
Non loggare mai password in chiaro!
Usare variabili ambiente per le credenziali:
"ConnectionString": "Server=sql01;Database=ProdDB;User Id=${DB_USER};Password=${DB_PASS}"
« <- Avviare server | -> Health Check »
Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional