cambio user di partenza

This commit is contained in:
Gaetano Savo 2025-05-23 19:17:38 +02:00
parent 3a3731dfeb
commit 2263d0e673
2 changed files with 39 additions and 18 deletions

View File

@ -7,8 +7,8 @@ if (-not (Test-Path $env:logDir)) {
New-Item -ItemType Directory -Path $env:logDir | Out-Null New-Item -ItemType Directory -Path $env:logDir | Out-Null
} }
$sqlbase = Join-Path $env:workdir "sql" $sqlbase = Join-Path $env:workdir "sql"
$env:dbUser = "F701264" $env:dbUser = "sa"
$env:dbPassword = "contrsei" $env:dbPassword = "_p1sap1a"
$env:dbHost = "DATABASE_PDC_LOCALE" $env:dbHost = "DATABASE_PDC_LOCALE"
$scriptName = $MyInvocation.MyCommand.Name $scriptName = $MyInvocation.MyCommand.Name
$logFile = Join-Path $env:logDir "${scriptName}.log" # for debug $logFile = Join-Path $env:logDir "${scriptName}.log" # for debug
@ -16,9 +16,9 @@ $logFile = Join-Path $env:logDir "${scriptName}.log" # for debug
# List of SQL files to execute in order # List of SQL files to execute in order
$sqlFiles = @( $sqlFiles = @(
# "C6SC01_creadb.sql", "C6SC01_creadb.sql",
# "C6SC08_creauser.sql", "C6SC08_creauser.sql",
# "StampeCentralizzateBackupRidotto.sql", "StampeCentralizzateBackupRidotto.sql",
"dbo.LogN.sql", "dbo.LogN.sql",
"" ""
) )
@ -59,12 +59,12 @@ foreach ($fileName in $sqlFiles) {
$(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" $esitoComando" $(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" $esitoComando"
$(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" ERROR per $fileSql, risultato in $fileLog " | Out-File -FilePath $logFile -Append $(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" ERROR per $fileSql, risultato in $fileLog " | Out-File -FilePath $logFile -Append
$(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" processo bloccato " | Out-File -FilePath $logFile -Append $(Get-Date -Format "yyyy-MM-dd_HH:mm:ss")+" processo bloccato " | Out-File -FilePath $logFile -Append
if ($retryCount -lt $maxRetries - 1) { # if ($retryCount -lt $maxRetries - 1) {
$retryCount++ # $retryCount++
Write-Host "Retry attempt $retryCount after 2 seconds..." # Write-Host "Retry attempt $retryCount after 2 seconds..."
Start-Sleep -Seconds 2 # Start-Sleep -Seconds 2
continue # continue
} # }
exit 1 exit 1
} }
$success = $true $success = $true

View File

@ -1,12 +1,33 @@
-- Creazione dell'utente F701264 con tutti i permessi
USE [master]
GO
-- Crea il login se non esiste
IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = 'F701264')
BEGIN
CREATE LOGIN [F701264] WITH PASSWORD = 'contrsei'
END
GO
-- Assegna i ruoli server
ALTER SERVER ROLE [sysadmin] ADD MEMBER [F701264]
GO
-- Per ogni database nel sistema, assegna i permessi necessari
USE [C6StampeCentralizzate] USE [C6StampeCentralizzate]
GO GO
-- Creare il login IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = 'F701264')
CREATE LOGIN [F701264] WITH PASSWORD = 'contrsei' DEFAULT_SCHEMA=[dbo] BEGIN
CREATE USER [F701264] FOR LOGIN [F701264]
END
-- Assegna il ruolo db_owner
ALTER ROLE [db_owner] ADD MEMBER [F701264]
GO GO
-- Creare l'utente associato al login -- Concedi permessi specifici
CREATE USER [F701264] FOR LOGIN [F701264] WITH DEFAULT_SCHEMA=[dbo] GRANT CONTROL TO [F701264]
-- Assegnare ruolo db_owner per controllo completo sul database GRANT VIEW DEFINITION TO [F701264]
ALTER ROLE [db_owner] ADD MEMBER [F701264] GRANT SHOWPLAN TO [F701264]
GO GO