Skip to content

Conversation

apoorvdeshmukh
Copy link
Contributor

sqlcmd when invoked with no arguments, executes in backward compat mode and ignore current-context info for establishing connection. This commit changes the default behavior to establish connection to the endpoint associated with current-context if valid user details exits in sqlcmd config file.
This ensures that users can connect to sql server instance created by sqlcmd if no arguments are specified while invoking sqlcmd.

\git\go-sqlcmd>.\sqlcmd.exe
1> select @@servername
2> go

--------------------------------------------------------------------------------------------------------------------------------
LAPTOP-VPBI3ASB

(1 row affected)
1> exit

git\go-sqlcmd>.\sqlcmd.exe create mssql --accept-eula
Downloading mcr.microsoft.com/mssql/server:latest
Starting mcr.microsoft.com/mssql/server:latest
Created context "mssql" in "C:\Users\apdeshmukh\.sqlcmd\sqlconfig", configuring user account...
Disabled "sa" account (and rotated "sa" password). Creating user "apdeshmukh"
Now ready for client connections on port 1435

HINT:
  1. Open in Azure Data Studio: sqlcmd open ads
  2. Run a query:               sqlcmd query "SELECT @@version"
  3. Start interactive session: sqlcmd query
  4. View sqlcmd configuration: sqlcmd config view
  5. See connection strings:    sqlcmd config connection-strings
  6. Remove:                    sqlcmd delete


\git\go-sqlcmd>.\sqlcmd.exe
1> select @@servername
2> go

--------------------------------------------------------------------------------------------------------------------------------
4ee585f27077

(1 row affected)
1>

sqlcmd when invoked with no arguments, executes in backward compat
mode and ignore current-context info for establishing connection.
This commit changes the default behavior to establish connection
to the endpoint associated with current-context if valid user details
exits in sqlcmd config file.
This ensures that users can connect to sql server instance created by
sqlcmd if no arguments are specified while invoking sqlcmd.
@stuartpa
Copy link
Collaborator

stuartpa commented Feb 28, 2023

  legacyCmd.Execute(version)

Move this call to the else statement below (right now we only need this envvars when running in legacy mode)


In reply to: 1447954442


In reply to: 1447954442


Refers to: cmd/modern/main.go:49 in 2f1a322. [](commit_id = 2f1a322, deletion_comment = False)

Copy link
Collaborator

@stuartpa stuartpa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes as discussed earlier

Earlier commit was setting env vars only if endpoint and user info
was associated with context. Context however may or may not have
user associated with it if end user wants to use trusted authentication.
In this commit, we are setting only the available info and inform user
of context being used
@apoorvdeshmukh
Copy link
Contributor Author

Changes as discussed earlier

Incorporated the changes which we discussed earlier.
Now we are setting only those env variables for which info is available in context such as endpoint and skipping others such as user details if not available (in case context is to be used for trusted authentication)

@apoorvdeshmukh
Copy link
Contributor Author

  legacyCmd.Execute(version)

Move this call to the else statement below (right now we only need this envvars when running in legacy mode)

Refers to: cmd/modern/main.go:49 in 2f1a322. [](commit_id = 2f1a322, deletion_comment = False)

Fixed

Copy link
Collaborator

@shueybubbles shueybubbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Collaborator

@stuartpa stuartpa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@apoorvdeshmukh apoorvdeshmukh merged commit a44d32d into main Mar 1, 2023
@apoorvdeshmukh apoorvdeshmukh deleted the apoorvdeshmukh/217 branch March 1, 2023 04:44
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

Successfully merging this pull request may close these issues.

Behavior of sqlcmd (with no sub-commands / or flags) moving forward
3 participants