go-sqlcmd
go-sqlcmd copied to clipboard
SqlCmd 1.5.0 Access Denied in Elevation mode against WID - Work fine with old SqlCmd 15 (SQL2019)
I use SQLCMD since many years to launch scripts on Microsoft WSUS databases (WID) like backup, shrink, etc.
Sinc some years I used the SQLCMD from "SQL Command Line Utilities 15" (MsSqlCmdLnUtils64.msi) and I never had issue. Everything is working fine.
I decided to move with SqlCmd 1.5.0 (latest vesion) to be up-to-date, security fixes. But he didn't work.
Due to a WID database limitation where it's not work in network and need administrator elevation, with old SqlCmd.exe I work like that:
1- Open a Command Line in elevation mode 2- Go to the SqlCmd Binn folder (C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.exe). Version 15.0.2000.5 3- Type the command line to run my action. In this sample I will run a T-SQL script to shrink the database: sqlcmd -S np:\.\pipe\MICROSOFT##WID\tsql\query -i "C:\script\shrink.sql" -o "C:\Script\shrink.log"
The content of the shrink.sql is: USE [SUSDB] GO DBCC SHRINKDATABASE(N'SUSDB') GO DBCC SHRINKFILE(N'SUSDB', 0, TRUNCATEONLY) GO
4- Everything work fine ! The database and files are shrinked !!!
If I install SqlCmd 1.5.0, I run the same command line, The I got in the log file: Access denied Access denied
It seem SqlCmd 1.5.0 have difficulties to connect.
https://www.sqlshack.com/managing-the-windows-internal-database-wid/
If you run the command with "--driver-logging-level 255" do we get more info on what is failing? (I don't have WID set up on my local machine)
The issue could be how sqlcmd or go-mssqldb converts . to localhost
ODBC passes the named pipe path verbatim to CreateFile, while Go sqlcmd passes \\localhost\pipe\microsoft##wid\tsql\query
I don't know why WID's instance would block it but SQL instances do not:
C:\git\go-sqlcmd\cmd\modern>modern -S np:\\.\pipe\sql\query -Q "select 1"
-----------
1
(1 row affected)
This bug is still present in version 1.6.0, is there any ETA when this get's fixed?
This bug is still present in version 1.6.0, is there any ETA when this get's fixed?
Seems to be sorted for me on the v1.8.0 version.... sqlcmd-windows-amd64.zip.