I am trying to connect my golang program to a mssql server that I run on a container using docker. the golang is also running on a docker container. the go script seems to be able to successfully connect to the database, but can't perform any operation on it. So,
db, err := sql.Open("mysql","SA:YourStrong!Passw0rd@tcp(127.0.0.1:1433)/")
if err != nil {
panic(err)
}
defer db.Close()
fmt.Println("Success open database")
This prints out the "success open database", however the next portion of the code throws a panic,
_,err = db.Exec("CREATE DATABASE currency1")
if err != nil {
panic(err)
}
fmt.Println("Success CREATE database")
After using docker to build and run it, this is what I got
GO MYSQL START
Success open database
panic: dial tcp 127.0.0.1:1433: getsockopt: connection refused
This is the command I used to run the mssql
database:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' -e 'MSSQL_PID=Express' -p 1433:1433 --name sql1 -d microsoft/mssql-server-linux:latest