microsoft / microsoft/go-sqlcmd

RAISERROR ('Message', 20, 1) WITH LOG causes SQLCMD to hang

Open
#785 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
595
Forks
91
Avg merge
9h 35m
Merged PRs (30d)
1

Description

When you execute the following command using a sysadmin account, SQLCMD hangs:

RAISERROR ('Message', 20, 1) WITH LOG

Noted this was mentioned in https://github.com/microsoft/go-sqlcmd/issues/76
That issue was closed with only a partial resolution to the issue.

Problem is caused by SQL Server forcibly terminating the connection - go-sqlcmd doesn't realise this has happened so gets into an undefined state and never exits.

https://learn.microsoft.com/en-us/sql/t-sql/language-elements/raiserror-transact-sql?view=sql-server-ver17

"Severity levels from 20 through 25 are considered fatal. If a fatal severity level is encountered, the client connection is terminated after receiving the message, and the error is logged in the error and application logs."

Workaround for me is to set the third parameter of RAISERROR (state) to 127 rather than 1 - but I'd rather it worked the same as ODBC sqlcmd does!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the RAISERROR ('Message', 20, 1) WITH LOG command in go-sqlcmd with a sysadmin account, then compare its behavior with ODBC sqlcmd and review the partial resolution in microsoft/go-sqlcmd#76. Trace how go-sqlcmd detects the SQL Server connection termination; done means the command reports the fatal error and exits instead of hanging.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.