Aggiunto DB bfdskreport02p
This commit is contained in:
parent
5d6841891b
commit
3692d71086
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
logs/
|
logs/
|
||||||
transito/
|
transito/
|
||||||
localhost/
|
localhost/
|
||||||
|
stored/
|
||||||
# extract/
|
# extract/
|
@ -19,6 +19,9 @@ Questo progetto contiene gli script e le procedure necessarie per la creazione e
|
|||||||
## Script Disponibili
|
## Script Disponibili
|
||||||
|
|
||||||
- `creadb.ps1` - Crea il database e le tabelle
|
- `creadb.ps1` - Crea il database e le tabelle
|
||||||
|
- `-UseDoneFolder` - Sposta i file SQL eseguiti con successo nella cartella 'done'
|
||||||
|
- `-LeaveSuccessLogs` - Mantiene i file di log anche in caso di successo
|
||||||
|
- `-DeleteSuccessSql` - Elimina i file SQL dopo l'esecuzione con successo
|
||||||
- `esporta.ps1` - Esporta una tabella in formato CSV
|
- `esporta.ps1` - Esporta una tabella in formato CSV
|
||||||
- `importa.ps1` - Importa una tabella da un file CSV
|
- `importa.ps1` - Importa una tabella da un file CSV
|
||||||
- `copia.ps1` - Copia una tabella da un ambiente all'altro (combina esporta e importa)
|
- `copia.ps1` - Copia una tabella da un ambiente all'altro (combina esporta e importa)
|
||||||
@ -37,4 +40,4 @@ Questo progetto contiene gli script e le procedure necessarie per la creazione e
|
|||||||
|
|
||||||
## Ultimo Aggiornamento
|
## Ultimo Aggiornamento
|
||||||
|
|
||||||
Data: 6 Giugno 2025
|
Data: 19 Giugno 2025
|
||||||
|
@ -3,17 +3,25 @@ $config = @{
|
|||||||
# Credenziali database
|
# Credenziali database
|
||||||
# DbUser = "sa"
|
# DbUser = "sa"
|
||||||
# DbPassword = "_p1sap1a"
|
# DbPassword = "_p1sap1a"
|
||||||
|
# DbUser = "SEIReport"
|
||||||
|
# DbPassword = "SEIReport"
|
||||||
DbUser = "F701264"
|
DbUser = "F701264"
|
||||||
DbPassword = "contrsei"
|
DbPassword = "contrsei"
|
||||||
|
|
||||||
|
# DbHostOutput
|
||||||
DbHostOutput = "DATABASE_PDC_LOCALE"
|
DbHostOutput = "DATABASE_PDC_LOCALE"
|
||||||
# DbHostOutput = "testbes.armundia.com"
|
# DbHostOutput = "testbes.armundia.com"
|
||||||
DbHostInput = "bfdskrepsei01c.sysfideuram.sysbancafideuram.it"
|
|
||||||
|
# DbHostInput
|
||||||
|
# DbHostInput = "bfdskrepsei01c.sysfideuram.sysbancafideuram.it"
|
||||||
# DbHostInput = "testbes.armundia.com"
|
# DbHostInput = "testbes.armundia.com"
|
||||||
# DbHostInput = "DATABASE_PDC_LOCALE"
|
# DbHostInput = "DATABASE_PDC_LOCALE"
|
||||||
# DbHostInput = "bfdskreport01p.fideuram.bancafideuram.it"
|
DbHostInput = "bfdskreport01p.fideuram.bancafideuram.it"
|
||||||
|
# DbHostInput = "bfdskreport02p.fideuram.bancafideuram.it"
|
||||||
# DbName = "master"
|
# DbName = "master"
|
||||||
ServerName = "CONSUNI"
|
ServerName = "CONSUNI"
|
||||||
DbName = "C6StampeCentralizzate"
|
DbName = "C6StampeCentralizzate"
|
||||||
|
# DbName = "SEIReport"
|
||||||
|
|
||||||
# Directory di log
|
# Directory di log
|
||||||
WorkDir = Split-Path -Path $PSScriptRoot -Parent
|
WorkDir = Split-Path -Path $PSScriptRoot -Parent
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
param(
|
param(
|
||||||
[switch]$UseDoneFolder = $false,
|
[switch]$UseDoneFolder,
|
||||||
[switch]$DeleteSuccessLogs = $true
|
[switch]$LeaveSuccessLogs,
|
||||||
|
[switch]$DeleteSuccessSql
|
||||||
)
|
)
|
||||||
|
|
||||||
# Importa configurazione
|
# Importa configurazione
|
||||||
@ -12,13 +13,14 @@ $logFile = Join-Path $env:logDir "${scriptName}.log" # for debug
|
|||||||
|
|
||||||
# List of SQL files or folders to execute in order
|
# List of SQL files or folders to execute in order
|
||||||
$sqlFiles = @(
|
$sqlFiles = @(
|
||||||
# "C6SC01_creadb.sql", # file singolo
|
# "base\C6SC01_creadb.sql", # file singolo
|
||||||
# "C6SC08_creauser.sql",
|
# "C6SC08_creauser.sql",
|
||||||
# "StampeCentralizzateBackupRidotto.sql",
|
# "base\StampeCentralizzateBackupRidotto.sql",
|
||||||
# "enable_sa_full.sql",
|
# "base\enable_sa_full.sql",
|
||||||
# "add_linked_server.sql",
|
# "base\add_linked_server.sql",
|
||||||
# "enable_F701264_full.sql",
|
# "base\enable_F701264_full.sql",
|
||||||
# "stored", # cartella
|
# "C6MartPeriodico_GESTIONE_SELECT_S80_FASE2_CU_20190206_preMioFoglio.sql",
|
||||||
|
"stored", # cartella
|
||||||
# "tables_from_select", # cartella
|
# "tables_from_select", # cartella
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
@ -80,24 +82,64 @@ foreach ($fileSql in $filesToExecute) {
|
|||||||
$retryCount = 0
|
$retryCount = 0
|
||||||
$success = $false
|
$success = $false
|
||||||
|
|
||||||
|
$success = $false
|
||||||
while (-not $success -and $retryCount -lt $maxRetries) {
|
while (-not $success -and $retryCount -lt $maxRetries) {
|
||||||
# try {
|
try {
|
||||||
# Execute the SQL file using sqlcmd
|
# Execute SQL and capture all output
|
||||||
sqlcmd -S $env:dbHostOutput -U $env:dbUser -P $env:dbPassword -d $env:dbName -i $fileSql >$fileLog 2>&1
|
$output = & sqlcmd -S $env:dbHostOutput -U $env:dbUser -P $env:dbPassword -d $env:dbName -i $fileSql -b 2>&1
|
||||||
$esitoComando = $LASTEXITCODE
|
$esitoComando = $LASTEXITCODE
|
||||||
|
|
||||||
|
# Save output to log file and process it
|
||||||
|
$output | Out-File -FilePath $fileLog
|
||||||
|
$logContent = Get-Content -Path $fileLog -Raw
|
||||||
|
|
||||||
|
# Check for SQL errors
|
||||||
|
if ($logContent -match "(Msg \d+,.*?)(?=Msg \d+,|$)|(Il nome della colonna.*?)(?=Msg \d+,|$)|(Errore di sintassi.*?)(?=Msg \d+,|$)") {
|
||||||
|
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ERRORE nell'esecuzione di $fileName" | Out-File -FilePath $logFile -Append
|
||||||
|
"------------------" | Out-File -FilePath $logFile -Append
|
||||||
|
$Matches[0].Trim() | Out-File -FilePath $logFile -Append
|
||||||
|
"----------------------------------------" | Out-File -FilePath $logFile -Append
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($esitoComando -ne 0) {
|
||||||
|
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ERRORE nell'esecuzione di $fileName (Exit Code: $esitoComando)" | Out-File -FilePath $logFile -Append
|
||||||
|
"------------------" | Out-File -FilePath $logFile -Append
|
||||||
|
$logContent | Out-File -FilePath $logFile -Append
|
||||||
|
"----------------------------------------" | Out-File -FilePath $logFile -Append
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
$success = $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ERRORE nell'esecuzione di $fileName" | Out-File -FilePath $logFile -Append
|
||||||
|
"------------------" | Out-File -FilePath $logFile -Append
|
||||||
|
$_.Exception.Message | Out-File -FilePath $logFile -Append
|
||||||
|
"----------------------------------------" | Out-File -FilePath $logFile -Append
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
# Leggi il contenuto del file di log
|
# Leggi il contenuto del file di log
|
||||||
$logContent = Get-Content -Path $fileLog -Raw
|
$logContent = Get-Content -Path $fileLog -Raw
|
||||||
|
|
||||||
# Controlla vari tipi di messaggi
|
# Controlla vari tipi di messaggi e errori
|
||||||
$isObjectExistsError = $logContent -match "There is already an object named"
|
$isObjectExistsError = $logContent -match "There is already an object named"
|
||||||
$hasWarnings = $logContent -match "(?m)^Warning:"
|
$hasWarnings = $logContent -match "(?m)^Warning:"
|
||||||
|
$hasErrors = $logContent -match "(?m)^Msg \d+, Level \d+, State \d+" -or
|
||||||
|
$logContent -match "Incorrect syntax" -or
|
||||||
|
$logContent -match "Invalid object name" -or
|
||||||
|
$logContent -match "Could not find stored procedure" -or
|
||||||
|
$logContent -match "Login failed"
|
||||||
$warningLines = if ($hasWarnings) {
|
$warningLines = if ($hasWarnings) {
|
||||||
$logContent -split "`n" | Where-Object { $_ -match "^Warning:" }
|
$logContent -split "`n" | Where-Object { $_ -match "^Warning:" }
|
||||||
} else { @() }
|
} else { @() }
|
||||||
|
$errorLines = if ($hasErrors) {
|
||||||
|
($logContent -split "`n" | Where-Object { $_ -match "^Msg \d+,|^Incorrect syntax|^Invalid object|^Could not find|^Login failed" }) -join "`n"
|
||||||
|
} else { "" }
|
||||||
"logSqlApp: $logSqlApp esitoComando: $esitoComando" | Out-File -FilePath $logFile -Append
|
"logSqlApp: $logSqlApp esitoComando: $esitoComando" | Out-File -FilePath $logFile -Append
|
||||||
|
|
||||||
IF ($esitoComando -eq 0 -or $isObjectExistsError) {
|
IF (($esitoComando -eq 0 -or $isObjectExistsError) -and -not $hasErrors) {
|
||||||
# Determina lo stato dell'esecuzione
|
# Determina lo stato dell'esecuzione
|
||||||
$status = if ($isObjectExistsError) {
|
$status = if ($isObjectExistsError) {
|
||||||
"SKIP"
|
"SKIP"
|
||||||
@ -119,13 +161,16 @@ foreach ($fileSql in $filesToExecute) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Eseguito con successo $fileName" -ForegroundColor Green
|
Write-Host "Eseguito con successo $fileName" -ForegroundColor Green
|
||||||
# Cancella il log file solo se richiesto e non ci sono warning ed errori
|
# Cancella il log file se non è richiesto di mantenerlo e non ci sono warning ed errori
|
||||||
if ($DeleteSuccessLogs) {
|
if (-not $LeaveSuccessLogs) {
|
||||||
Remove-Item -Path $fileLog -Force
|
Remove-Item -Path $fileLog -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sposta il file SQL nella directory done se richiesto
|
# Gestione del file SQL dopo l'esecuzione con successo
|
||||||
if ($UseDoneFolder) {
|
if ($DeleteSuccessSql) {
|
||||||
|
Remove-Item -Path $fileSql -Force
|
||||||
|
Write-Host " File SQL eliminato" -ForegroundColor Gray
|
||||||
|
} elseif ($UseDoneFolder) {
|
||||||
$destPath = Join-Path $doneDir $fileName
|
$destPath = Join-Path $doneDir $fileName
|
||||||
Move-Item -Path $fileSql -Destination $destPath -Force
|
Move-Item -Path $fileSql -Destination $destPath -Force
|
||||||
Write-Host " File spostato in done/" -ForegroundColor Gray
|
Write-Host " File spostato in done/" -ForegroundColor Gray
|
||||||
@ -135,7 +180,11 @@ foreach ($fileSql in $filesToExecute) {
|
|||||||
} else {
|
} else {
|
||||||
Write-Host "ERRORE nell'esecuzione di $fileName" -ForegroundColor Red
|
Write-Host "ERRORE nell'esecuzione di $fileName" -ForegroundColor Red
|
||||||
Write-Host "Log dell'errore:" -ForegroundColor Red
|
Write-Host "Log dell'errore:" -ForegroundColor Red
|
||||||
|
if ($errorLines) {
|
||||||
|
Write-Host $errorLines -ForegroundColor Red
|
||||||
|
} else {
|
||||||
Write-Host $logContent -ForegroundColor Red
|
Write-Host $logContent -ForegroundColor Red
|
||||||
|
}
|
||||||
Write-Host "----------------------------------------" -ForegroundColor Red
|
Write-Host "----------------------------------------" -ForegroundColor Red
|
||||||
|
|
||||||
$(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" ERROR per $fileSql" | Out-File -FilePath $logFile -Append
|
$(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" ERROR per $fileSql" | Out-File -FilePath $logFile -Append
|
||||||
|
@ -3,13 +3,17 @@
|
|||||||
. $PSScriptRoot\conf.ps1
|
. $PSScriptRoot\conf.ps1
|
||||||
|
|
||||||
# Imposta il percorso di output nella cartella sql
|
# Imposta il percorso di output nella cartella sql
|
||||||
$OutputPath = Join-Path $env:workdir "sql\stored"
|
$OutputPath = Join-Path $env:workdir "transito"
|
||||||
|
|
||||||
# Importa il modulo SQL Server se non è già caricato
|
# Verifica e installa il modulo SqlServer se necessario
|
||||||
if (-not (Get-Module -Name SQLPS)) {
|
if (-not (Get-Module -ListAvailable -Name SqlServer)) {
|
||||||
Import-Module SQLPS -DisableNameChecking
|
Write-Host "Installazione del modulo SqlServer..."
|
||||||
|
Install-Module -Name SqlServer -Force -AllowClobber -Scope CurrentUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Importa il modulo SqlServer
|
||||||
|
Import-Module SqlServer -DisableNameChecking
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# Query per ottenere l'elenco degli oggetti
|
# Query per ottenere l'elenco degli oggetti
|
||||||
$query = @"
|
$query = @"
|
||||||
@ -30,7 +34,8 @@ try {
|
|||||||
"@
|
"@
|
||||||
|
|
||||||
# Esegui la query e salva i risultati
|
# Esegui la query e salva i risultati
|
||||||
$results = Invoke-Sqlcmd -ServerInstance $config.DbHostInput -Database $config.DbName -Username $config.DbUser -Password $config.DbPassword -Query $query
|
$connectionString = "Server=$($config.DbHostInput);Database=$($config.DbName);User Id=$($config.DbUser);Password=$($config.DbPassword);TrustServerCertificate=True"
|
||||||
|
$results = Invoke-Sqlcmd -ConnectionString $connectionString -Query $query
|
||||||
|
|
||||||
# Prepara l'output
|
# Prepara l'output
|
||||||
$output = "Elenco oggetti del database $($config.DbName) su $($config.DbHostInput) il $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`r`n"
|
$output = "Elenco oggetti del database $($config.DbName) su $($config.DbHostInput) il $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`r`n"
|
||||||
|
@ -6,7 +6,7 @@ $logFile = Join-Path $env:logDir "${scriptName}.log"
|
|||||||
"start" | Out-File -FilePath $logFile
|
"start" | Out-File -FilePath $logFile
|
||||||
|
|
||||||
# Imposta il percorso di output nella cartella sql
|
# Imposta il percorso di output nella cartella sql
|
||||||
$OutputPath = Join-Path $env:workdir "sql\tables"
|
$OutputPath = Join-Path $env:workdir "transito\tables"
|
||||||
|
|
||||||
# Verifica che la directory di output esista, altrimenti la crea
|
# Verifica che la directory di output esista, altrimenti la crea
|
||||||
if (-not (Test-Path -Path $OutputPath)) {
|
if (-not (Test-Path -Path $OutputPath)) {
|
||||||
@ -22,47 +22,55 @@ try {
|
|||||||
# Query per estrarre la definizione delle tabelle
|
# Query per estrarre la definizione delle tabelle
|
||||||
$query = @"
|
$query = @"
|
||||||
WITH TableColumns AS (
|
WITH TableColumns AS (
|
||||||
SELECT
|
SELECT DISTINCT
|
||||||
t.object_id,
|
t.object_id,
|
||||||
STRING_AGG(
|
(
|
||||||
CONCAT(
|
SELECT STUFF((
|
||||||
CHAR(9), '[', c.name, '] ',
|
SELECT ',' + CHAR(13) + CHAR(10) +
|
||||||
|
CHAR(9) + '[' + c2.name + '] ' +
|
||||||
CASE
|
CASE
|
||||||
WHEN t2.name IN ('char', 'varchar', 'nchar', 'nvarchar')
|
WHEN t2.name IN ('char', 'varchar', 'nchar', 'nvarchar')
|
||||||
THEN t2.name + '(' +
|
THEN t2.name + '(' +
|
||||||
CASE
|
CASE
|
||||||
WHEN c.max_length = -1 THEN 'MAX'
|
WHEN c2.max_length = -1 THEN 'MAX'
|
||||||
WHEN t2.name LIKE 'n%' THEN CAST(c.max_length/2 AS VARCHAR)
|
WHEN t2.name LIKE 'n%' THEN CAST(c2.max_length/2 AS VARCHAR)
|
||||||
ELSE CAST(c.max_length AS VARCHAR)
|
ELSE CAST(c2.max_length AS VARCHAR)
|
||||||
END + ')'
|
END + ')'
|
||||||
WHEN t2.name IN ('decimal', 'numeric')
|
WHEN t2.name IN ('decimal', 'numeric')
|
||||||
THEN t2.name + '(' + CAST(c.[precision] AS VARCHAR) + ',' + CAST(c.[scale] AS VARCHAR) + ')'
|
THEN t2.name + '(' + CAST(c2.[precision] AS VARCHAR) + ',' + CAST(c2.[scale] AS VARCHAR) + ')'
|
||||||
ELSE t2.name
|
ELSE t2.name
|
||||||
END,
|
END +
|
||||||
CASE WHEN c.is_nullable = 0 THEN ' NOT NULL' ELSE ' NULL' END,
|
CASE WHEN c2.is_nullable = 0 THEN ' NOT NULL' ELSE ' NULL' END +
|
||||||
CASE WHEN ic.is_identity = 1 THEN ' IDENTITY(' + CAST(IDENT_SEED(OBJECT_SCHEMA_NAME(t.object_id) + '.' + OBJECT_NAME(t.object_id)) AS VARCHAR) + ',' + CAST(IDENT_INCR(OBJECT_SCHEMA_NAME(t.object_id) + '.' + OBJECT_NAME(t.object_id)) AS VARCHAR) + ')' ELSE '' END,
|
CASE WHEN ic.is_identity = 1 THEN ' IDENTITY(' + CAST(IDENT_SEED(OBJECT_SCHEMA_NAME(t.object_id) + '.' + OBJECT_NAME(t.object_id)) AS VARCHAR) + ',' + CAST(IDENT_INCR(OBJECT_SCHEMA_NAME(t.object_id) + '.' + OBJECT_NAME(t.object_id)) AS VARCHAR) + ')' ELSE '' END +
|
||||||
CASE WHEN dc.definition IS NOT NULL THEN ' DEFAULT ' + dc.definition ELSE '' END
|
CASE WHEN dc.definition IS NOT NULL THEN ' DEFAULT ' + dc.definition ELSE '' END
|
||||||
),
|
FROM sys.columns c2
|
||||||
',' + CHAR(13) + CHAR(10)
|
INNER JOIN sys.types t2 ON c2.user_type_id = t2.user_type_id
|
||||||
) WITHIN GROUP (ORDER BY c.column_id) as ColumnDefinitions
|
LEFT JOIN sys.identity_columns ic ON ic.object_id = c2.object_id AND ic.column_id = c2.column_id
|
||||||
|
LEFT JOIN sys.default_constraints dc ON dc.parent_object_id = c2.object_id AND dc.parent_column_id = c2.column_id
|
||||||
|
WHERE c2.object_id = t.object_id
|
||||||
|
ORDER BY c2.column_id
|
||||||
|
FOR XML PATH('')
|
||||||
|
), 1, 2, '')
|
||||||
|
) as ColumnDefinitions
|
||||||
FROM sys.tables t
|
FROM sys.tables t
|
||||||
INNER JOIN sys.columns c ON c.object_id = t.object_id
|
|
||||||
INNER JOIN sys.types t2 ON c.user_type_id = t2.user_type_id
|
|
||||||
LEFT JOIN sys.identity_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
|
|
||||||
LEFT JOIN sys.default_constraints dc ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id
|
|
||||||
GROUP BY t.object_id
|
|
||||||
),
|
),
|
||||||
TablePrimaryKeys AS (
|
TablePrimaryKeys AS (
|
||||||
SELECT
|
SELECT DISTINCT
|
||||||
i.object_id,
|
i.object_id,
|
||||||
CHAR(13) + CHAR(10) + 'ALTER TABLE [' + OBJECT_SCHEMA_NAME(i.object_id) + '].[' + OBJECT_NAME(i.object_id) + '] ADD CONSTRAINT [' + i.name + '] PRIMARY KEY ' +
|
(
|
||||||
|
SELECT CHAR(13) + CHAR(10) + 'ALTER TABLE [' + OBJECT_SCHEMA_NAME(i.object_id) + '].[' + OBJECT_NAME(i.object_id) + '] ADD CONSTRAINT [' + i.name + '] PRIMARY KEY ' +
|
||||||
CASE WHEN i.type = 1 THEN 'CLUSTERED' ELSE 'NONCLUSTERED' END +
|
CASE WHEN i.type = 1 THEN 'CLUSTERED' ELSE 'NONCLUSTERED' END +
|
||||||
' (' + STRING_AGG(QUOTENAME(c.name), ',') WITHIN GROUP (ORDER BY ic.key_ordinal) + ')' as PkDefinition
|
' (' + STUFF((
|
||||||
|
SELECT ',' + QUOTENAME(c2.name)
|
||||||
|
FROM sys.index_columns ic2
|
||||||
|
INNER JOIN sys.columns c2 ON c2.object_id = ic2.object_id AND c2.column_id = ic2.column_id
|
||||||
|
WHERE ic2.object_id = i.object_id AND ic2.index_id = i.index_id
|
||||||
|
ORDER BY ic2.key_ordinal
|
||||||
|
FOR XML PATH('')
|
||||||
|
), 1, 1, '') + ')'
|
||||||
|
) as PkDefinition
|
||||||
FROM sys.indexes i
|
FROM sys.indexes i
|
||||||
INNER JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
||||||
INNER JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
||||||
WHERE i.is_primary_key = 1
|
WHERE i.is_primary_key = 1
|
||||||
GROUP BY i.object_id, i.name, i.type
|
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
s.name as SchemaName,
|
s.name as SchemaName,
|
||||||
@ -85,7 +93,31 @@ try {
|
|||||||
Write-Host "Eseguo query su $env:dbHostInput..."
|
Write-Host "Eseguo query su $env:dbHostInput..."
|
||||||
"Eseguo query su $env:dbHostInput..." | Out-File -FilePath $logFile -Append
|
"Eseguo query su $env:dbHostInput..." | Out-File -FilePath $logFile -Append
|
||||||
|
|
||||||
$tables = Invoke-Sqlcmd -ServerInstance $env:dbHostInput -Database $env:dbName -Query $query -Username $env:dbUser -Password $env:dbPassword -MaxCharLength 1000000 -TrustServerCertificate
|
$sqlParams = @{
|
||||||
|
ServerInstance = $env:dbHostInput
|
||||||
|
Database = $env:dbName
|
||||||
|
Query = $query
|
||||||
|
Username = $env:dbUser
|
||||||
|
Password = $env:dbPassword
|
||||||
|
MaxCharLength = 1000000
|
||||||
|
TrustServerCertificate = $true
|
||||||
|
ConnectionTimeout = 30
|
||||||
|
EncryptConnection = $true
|
||||||
|
ApplicationIntent = 'ReadOnly'
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Host "Tentativo di connessione a $($sqlParams.ServerInstance)..."
|
||||||
|
$tables = Invoke-Sqlcmd @sqlParams
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Errore di connessione al database: $($_.Exception.Message)"
|
||||||
|
Write-Host "Dettagli connessione:"
|
||||||
|
Write-Host "Server: $($sqlParams.ServerInstance)"
|
||||||
|
Write-Host "Database: $($sqlParams.Database)"
|
||||||
|
Write-Host "Utente: $($sqlParams.Username)"
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Trovate $($tables.Count) tabelle"
|
Write-Host "Trovate $($tables.Count) tabelle"
|
||||||
"Trovate $($tables.Count) tabelle" | Out-File -FilePath $logFile -Append
|
"Trovate $($tables.Count) tabelle" | Out-File -FilePath $logFile -Append
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user