Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlCmd 1.5.0 Access Denied in Elevation mode against WID - Work fine with old SqlCmd 15 (SQL2019) #506

Open
ggbce opened this issue Feb 6, 2024 · 4 comments

Comments

@ggbce
Copy link

ggbce commented Feb 6, 2024

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.

@stuartpa
Copy link
Collaborator

stuartpa commented Feb 7, 2024

@stuartpa
Copy link
Collaborator

stuartpa commented Feb 7, 2024

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)

@shueybubbles
Copy link
Collaborator

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)

@TheEarthrise
Copy link

This bug is still present in version 1.6.0, is there any ETA when this get's fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants