Sometimes (nigh, always) when you have to start a sql server in single user mode (the ‘/m’ after the net start…), executing queries in the sqlcmd prompt can be a bit of a painful endeavor. What I usually do is use powershell to stop the service, then restart the service in single-user mode and grab a serverconnection to it immediately in powershell_ise:
Import-Module SqlPS -DisableNameChecking cls Stop-Service -Name "MSSQL`$SQL2012" -Force net start "MSSQL`$SQL2012" /m $sqlcmd = New-Object Microsoft.SqlServer.Management.Common.ServerConnection '.\sql2012' $sqlcmd.Connect();
I can then reference the $sqlcmd object in other tabs in powershell_ise to work in a more pleasant environment:
Notice, I can’t connect in SSMS:
Just a helpful tip.