Home > Net >  Golang : "Err TLS Handshake failed: tls: server selected unsupported protocol version 301"
Golang : "Err TLS Handshake failed: tls: server selected unsupported protocol version 301"

Time:05-23

This my code when try to connect sql server:

https://img.codepudding.com/202205/10faec78b84e4faf84e543c35783e1ee.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?

CodePudding user response:

"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
  • Related