Skip to content

Instantly share code, notes, and snippets.

@urbim
Created October 10, 2024 15:52
Show Gist options
  • Select an option

  • Save urbim/6bfa8e8f5f5453666a7b5b75df02e156 to your computer and use it in GitHub Desktop.

Select an option

Save urbim/6bfa8e8f5f5453666a7b5b75df02e156 to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
"fmt"
"github.com/golang-migrate/migrate/v4/database/sqlserver"
)
func main() {
connectionString := "sqlserver://sa:some(!)Password@localhost:1433/golang_migrate_test"
db, err := sql.Open("sqlserver", connectionString)
if err != nil {
panic(err)
}
if err := db.Ping(); err != nil {
panic(err)
}
p := &sqlserver.SQLServer{}
d1, err := p.Open(connectionString) // d1
if err != nil {
panic(err)
}
err = d1.Lock()
if err != nil {
panic(err)
}
fmt.Print("Locked\n")
_, err = p.Open(connectionString) // d2
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment