2

This my code when try to connect sql server:

https://i.stack.imgur.com/2nBzN.png

connString := fmt.Sprintf("server=%s;user id=%s;password=%s¡port=%s;databases=%s", server, user, password, port, database)

// if there is an error opening the connection, handle it
if err != nil {
  // simply print the error to the console 
  fmt.Println("Err", err.Error())
}

err.Error()) // returna nit on error

defer db.Close()

results, err := db.query("SELECT employee_id, display_name from `person_tbl`")

if err != nil {
  fmt.Println("Err", err.Error())
}
fmt.Print (results)

When i try to connect to sql server, i get error message "Err TLS Handshake failed: tls: server selected unsupported protocol version 301" I have tried changing TLS to version 1.2 on the server and still getting the same error message. Do I need to reset my TLS again or do I need to add code to my Go-lang code?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Please don't add text (code, error) as image but instead include the actual text here. – Steffen Ullrich May 21 '22 at 07:03
  • All supported versions of Microsoft SQL Server support TLS 1.2 connectivity. What specific version of SQL Server are you attempting to connect to (what's the output of `SELECT @@VERSION`)? If you're using the `go-mssqldb` package you might also wish to read through [Go version 1.18 TLS 1.0 and 1.1 disabled by default client-side (sql server old TLS versions not work) #726](https://github.com/denisenkom/go-mssqldb/issues/726) – AlwaysLearning May 21 '22 at 07:53

2 Answers2

3

You must update Microsoft sql server to support the last TLS, or less secure, you can disable encrypt on connection string like example below.

connectionString: "sqlserver://user@SERVIDOR/SQL2012?database=dbexample&encrypt=disable&connection+timeout=30"
Rui Eusebio
  • 161
  • 1
  • 4
2

"unsupported protocol version" 301 means an insecure TLS version (1.0), selected by the server. (and 301: permanently redirected)

Make sure the Sql-server you are connecting to supports a recent TLS version (like a TLS 1.2 for a Microsoft SQL Server for instance).

I have tried changing TLS to version 1.2 on the server

Double-check this change was effective:

  • A) TLS1.0 --> curl -v -s --tlsv1.0 https://<instance-name> -o /dev/null/ 2>&1
  • B) TLS1.1 --> curl -v -s --tlsv1.1 https://<instance-name> -o /dev/null/ 2>&1
  • C) TLS1.2 --> curl -v -s https://<instance-name> -o /dev/null/ 2>&1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250