Last active
March 10, 2025 22:05
-
-
Save dfar-io/6d379321b70938fc41ab537914a1c455 to your computer and use it in GitHub Desktop.
Updates dataSettings.json on an IIS server for NopCommerce to switch databases and restart the app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Changes staging to use a newly restored database | |
#> | |
param ( | |
[Parameter(Mandatory, Position=0)][string]$newDbName | |
) | |
$appPoolName = 'NopAbc_Test' | |
$directory = 'C:\NopABC_Test' | |
$content = @" | |
{ | |
"DataConnectionString": "Data Source=192.168.253.223,1433;Initial Catalog=$newDbName;User ID=sa;Password=;Connection Timeout=300", | |
"DataProvider": "sqlserver", | |
"RawDataSettings": {} | |
} | |
"@ | |
# Specify the path where you want to save the file | |
$filePath = "$directory\App_Data\dataSettings.json" | |
# Ensure the directory exists; create it if it does not | |
$directory = [System.IO.Path]::GetDirectoryName($filePath) | |
if (-not (Test-Path -Path $directory)) { | |
New-Item -Path $directory -ItemType Directory -Force | |
} | |
# Write the content to the file | |
$content | Set-Content -Path $filePath | |
# Now stop and start the IIS App Pool | |
Stop-WebAppPool -Name $appPoolName | Out-Null | |
Write-Host 'App Pool Stopped.' | |
Start-Sleep -s 15 | |
Start-WebAppPool -Name $appPoolName -ErrorAction 'SilentlyContinue' | Out-Null | |
Write-Host 'App Pool Started.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment