I am currently using this example to connect to SQL Server using Go:
Create Go apps
Here is the example I am using:
package main
import (
_ "github.com/denisenkom/go-mssqldb"
"database/sql"
"context"
"log"
"fmt"
)
// Replace with your own connection parameters
var server = "localhost"
var port = 1433
var user = "sa"
var password = "your_password"
var db *sql.DB
func main() {
var err error
// Create connection string
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d",
server, user, password, port)
// Create connection pool
db, err = sql.Open("sqlserver", connString)
if err != nil {
log.Fatal("Error creating connection pool: " + err.Error())
}
log.Printf("Connected!\n")
// Close the database connection pool after program executes
defer db.Close()
SelectVersion()
}
Is there any known way to use Windows Authentication to connect to SQL Server? I have tried adding "Trusted_Connection=yes" and removing the username/password.
I have Googled around but have not found any Go Packages that have this option.
As I posted earlier...
"trusted_connection=yes" did work. I just entered it wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With