microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
334 stars 58 forks source link

Set context to on-premises SQL Server #323

Closed way0utwest closed 1 year ago

way0utwest commented 1 year ago

I do like the idea of a context. However, what I'd like to do is set a context to a local instance of SQL Server, not a containerized version. I would prefer something like

sqlcmd config set-context mssql -S localhost -D AdventureWorks

stuartpa commented 1 year ago

Sure, this works no problems. See sqlcmd config --help for an example of how to do this.

C:\>sqlcmd config --help
Modify sqlconfig files using subcommands like "sqlcmd config use-context mssql"

Usage:
  sqlcmd config [flags]
  sqlcmd config [command]

Examples:
# Add context for existing endpoint and user (use SQLCMD_PASSWORD or SQLCMDPASSWORD)
  SET SQLCMD_PASSWORD=<placeholderpassword>
  sqlcmd config add-user --name sa1434 --username sa
  SET SQLCMD_PASSWORD=
  sqlcmd config add-endpoint --name ep1434 --address localhost --port 1434
  sqlcmd config add-context --name mssql1434 --user sa1434 --endpoint ep1434
way0utwest commented 1 year ago

Then what I'd ask is better documentation. It's unclear what an endpoint is, nor it is clear that I ought to link the endpoint and context. Specifically, an example on https://learn.microsoft.com/en-us/sql/tools/sqlcmd/go-sqlcmd-utility?view=sql-server-ver16 that says this us for adding a local connection context. Same for the readme in the root of this repo.

I have verified this works.