Context
I have a powershell script that performs some setup for an application in a test environment. Among other things, the script calls sqlcmd
several times.
A few days ago, I performed a restore against the database. I used SQL Server Management Studio 20.2 to restore a BAK file to a local Microsoft SQL Server 2022 instance (all version info below). I did this using the SSMS Restore Database wizard with WITH REPLACE
, WITH_RESTRICTED_USER
, and closing existing connections to the database.
I then attempted to run my configuration script against this freshly restored database, as I've done successfully a hundred times before. The script begins by ensuring that sqlcmd is installed and up to date:
winget install sqlcmd
Next, it performs commands in the following format, where $Server is .\sqlexpress
and $Database may vary (so it does not appear to be a database-specific problem):
sqlcmd -S $Server -d $Database -E -Q "ALTER DATABASE..."
I do not specify whether to use TCP or named pipes - I just let it use the default.
Problem
Usually, each sqlcmd finishes in well under a second and outputs something along the lines of Commands completed successfully.
or (7653 rows affected)
, but instead, after around 45 seconds, I get the following output for every command (NB the same line is repeated twice for a single invocation of the command):
Timed out waiting for pipe '\\.\pipe\SQLLocal\sqlexpress' to come available
Timed out waiting for pipe '\\.\pipe\SQLLocal\sqlexpress' to come available
What I've Tried
Beyond the obvious verifications (SQL server instance is running, connection details are correct, etc), I've tried:
- Restoring the database again, and again closing any existing connections, to ensure that at least 1 connection was available
- Restarting the SQL server instance
- Restarting the entire machine
I tried running each SQL query "manually" from within SSMS, and each of them reported no errors and were observed to have the intended effect, however this process takes a long time, having to copy out every query and substitute in the variables, switching back to powershell every so often to run non-SQL commands.
Question(s)
What happened to cause sqlcmd to time out, and what can I change to ensure that it can run as it's supposed to / used to?
Version Info
SSMS version info:
SQL Server Management Studio 20.2.30.0
SQL Server Management Objects (SMO) 17.100.40.0+f57178c95d4376485d3f597f2b829bbd6f80fd6f
Microsoft T-SQL Parser 17.2.3.1+46115224c373754fdd41516eaae1386cabc4819e.46115224c373754fdd41516eaae1386cabc4819e
Microsoft Analysis Services Client Tools 20.0.3.0
Microsoft Data SqlClient (MDS) 5.1.5
Microsoft SQL Server Data-Tier Application Framework (DacFX) 162.3.566.1+89d89fe935702c8836ebaf6a03cf61b85118f847.89d89fe935702c8836ebaf6a03cf61b85118f847
Microsoft .NET Framework 4.0.30319.42000
Operating System 10.0.22631
SQL server (SELECT @@VERSION
):
Microsoft SQL Server 2022 (RTM-GDR) (KB5046861) - 16.0.1135.2 (X64) Oct 18 2024 15:31:58 Copyright (C) 2022 Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 22631: ) (Hypervisor)
Extract from Windows systeminfo
:
OS Name: Microsoft Windows 11 Enterprise
OS Version: 10.0.22631 N/A Build 22631
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free