7373 -Q "ALTER LOGIN sa WITH PASSWORD='${SA_PASSWORD}'"
7474 echo "BASE_CS=Server=localhost;User ID=sa;Password=${SA_PASSWORD};TrustServerCertificate=True;" >> "$GITHUB_ENV"
7575
76- # --- Windows setup: install SQL Server Express with SQL auth ---
76+ # --- Windows setup: install SQL Server Express, then enable SQL auth with sa ---
7777
7878 - name : Generate SA password (Windows)
7979 if : runner.os == 'Windows'
@@ -86,14 +86,38 @@ jobs:
8686 if : runner.os == 'Windows'
8787 shell : pwsh
8888 run : |
89- choco install sql-server-express -y --no-progress `
90- --params "/SECURITYMODE=SQL /SAPWD=$env:SA_PASSWORD /TCPENABLED=1"
91- # SQL Server Browser helps named-instance resolution; not strictly required when using a port
92- Set-Service -Name SQLBrowser -StartupType Manual -ErrorAction SilentlyContinue
93- Start-Service -Name SQLBrowser -ErrorAction SilentlyContinue
94- # Confirm the engine service is running
89+ choco install sql-server-express -y --no-progress
9590 Get-Service | Where-Object { $_.Name -like 'MSSQL*' } | Format-Table
9691
92+ - name : Enable mixed-mode auth and sa login (Windows)
93+ if : runner.os == 'Windows'
94+ shell : pwsh
95+ run : |
96+ # Find sqlcmd.exe (installed by Express)
97+ $sqlcmd = (Get-ChildItem 'C:\Program Files\Microsoft SQL Server' -Recurse -Filter sqlcmd.exe -ErrorAction SilentlyContinue |
98+ Select-Object -First 1).FullName
99+ if (-not $sqlcmd) { throw "sqlcmd.exe not found after SQL Express install" }
100+ Write-Host "Using sqlcmd at: $sqlcmd"
101+
102+ # Connect with Windows auth (runner is local admin), switch to mixed mode
103+ & $sqlcmd -S 'localhost\SQLEXPRESS' -E -b -Q @"
104+ EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
105+ N'Software\Microsoft\MSSQLServer\MSSQLServer',
106+ N'LoginMode', REG_DWORD, 2;
107+ " @
108+ if ($LASTEXITCODE -ne 0) { throw " Failed to set LoginMode" }
109+
110+ # Restart so LoginMode change takes effect
111+ Restart-Service 'MSSQL$SQLEXPRESS' -Force
112+
113+ # Enable the sa login and set its password
114+ & $sqlcmd -S 'localhost\SQLEXPRESS' -E -b -Q "ALTER LOGIN sa ENABLE; ALTER LOGIN sa WITH PASSWORD='$env:SA_PASSWORD';"
115+ if ($LASTEXITCODE -ne 0) { throw "Failed to enable/set sa login" }
116+
117+ # Verify SQL auth works
118+ & $sqlcmd -S 'localhost\SQLEXPRESS' -U sa -P $env:SA_PASSWORD -b -Q "SELECT @@VERSION"
119+ if ($LASTEXITCODE -ne 0) { throw "SQL auth verification failed" }
120+
97121 - name : Set connection string (Windows)
98122 if : runner.os == 'Windows'
99123 run : |
0 commit comments