Golang : "Err TLS Handshake failed: tls: server selected unsupported protocol version 301" when trying to connect to sql server (diferent host)

huangapple go评论82阅读模式
英文:

Golang : "Err TLS Handshake failed: tls: server selected unsupported protocol version 301" when trying to connect to sql server (diferent host)

问题

这是我尝试连接SQL Server时的代码:

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

// 如果打开连接时出现错误,处理错误
if err != nil {
  // 简单地将错误打印到控制台
  fmt.Println("Err", err.Error())
}

err.Error()) // 在错误时返回nil

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)

当我尝试连接到SQL Server时,我收到错误消息"Err TLS Handshake failed: tls: server selected unsupported protocol version 301"。我已经尝试将服务器的TLS更改为版本1.2,但仍然收到相同的错误消息。我需要再次重置我的TLS还是需要在我的Go语言代码中添加代码?

英文:

This my code when try to connect sql server:

Golang : "Err TLS Handshake failed: tls: server selected unsupported protocol version 301" when trying to connect to sql server (diferent host)

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?

答案1

得分: 3

你必须更新Microsoft SQL Server以支持最新的TLS版本,或者如果安全性要求较低,可以在连接字符串中禁用加密,例如下面的示例:

connectionString: "sqlserver://user@SERVIDOR/SQL2012?database=dbexample&encrypt=disable&connection+timeout=30"
英文:

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"

答案2

得分: 2

"unsupported protocol version" 301表示服务器选择了一个不安全的TLS版本(1.0)。请确保您连接的SQL服务器支持较新的TLS版本(例如,Microsoft SQL Server的TLS 1.2)。

我已经尝试在服务器上将TLS更改为1.2版本。

请仔细检查此更改是否生效:

  • 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
英文:

"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://&lt;instance-name&gt; -o /dev/null/ 2&gt;&amp;1

  • B) TLS1.1 --> curl -v -s --tlsv1.1 https://&lt;instance-name&gt; -o /dev/null/ 2&gt;&amp;1

  • C) TLS1.2 --> curl -v -s https://&lt;instance-name&gt; -o /dev/null/ 2&gt;&amp;1

huangapple
  • 本文由 发表于 2022年5月21日 14:20:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/72327173.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定