go

command module
v0.0.0-...-64d6a9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 6 Imported by: 0

README

MSSQL / SQL-Server logo

your MSSQL / SQL-Server connection deserves a name: Go edition

An example on how to assign a name to a MSSQL / SQL-Server connection in Go.

Get it running

  1. Start the SQL-Server docker container:
$ docker run --rm \
    --publish 1433:1433 \
    --name ycdan-sql-server \
    --env ACCEPT_EULA=Y \
    --env MSSQL_PID=Developer \
    --env 'SA_PASSWORD=yourStrong(!)Password' \
    --detach \
    mcr.microsoft.com/mssql/server:2019-CU12-ubuntu-20.04
  1. Compile the example program:
$ go build -o your-connection-deserves-a-name
  1. Start the example program:
$ ./your-connection-deserves-a-name

You should see something like

2021/08/14 10:47:55 Connecting to SQL-Server on sqlserver://sa:yourStrong%28%21%29Password@127.0.0.1:1433/?app+name=currency-conversion-app
2021/08/14 10:47:55 Connecting to SQL-Server on sqlserver://sa:yourStrong%28%21%29Password@127.0.0.1:1433/?app+name=currency-conversion-app ... Successful
2021/08/14 10:47:55
2021/08/14 10:47:55 Keeping the connection open ...
2021/08/14 10:47:55 You can connect to the SQL-Server database and execute the query:
2021/08/14 10:47:55 	SELECT hostname, program_name, loginame, cmd FROM sys.sysprocesses WHERE program_name != "";
2021/08/14 10:47:55 Hit CTRL + C or cancel the process to stop.
2021/08/14 10:47:55
  1. Login into your database and execute the query:
1> SELECT hostname, program_name, loginame, cmd FROM sys.sysprocesses WHERE program_name != "";
2> Go

hostname       program_name                  loginame       cmd
-------------- ----------------------------- -------------- ----------------------
lap-dev        currency-conversion-app       sa             AWAITING COMMAND

Don't know what this is all about?

Read the original blog post your database connection deserves a name @ andygrunwald.com.

Additionally, you can check out the projects README.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL