如何在 Hana DB 上连接 SSL - SAP [SQL 错误 4321 - 只允许安全连接]
How to connect SSL on Hana DB - SAP [SQL Error 4321 - only secure connections are allowed]
在 link SAP - Go (golang) Support 之后编写了以下代码:
package main
import (
"database/sql"
_ "github.com/SAP/go-hdb/driver"
"log"
)
const (
driverName = "hdb"
hdbDsn = "hdb://user:password@hostname:port"
)
func main() {
db, err := sql.Open(driverName, hdbDsn)
if err != nil {
log.Print("error on sql open => " ,err)
}
err = db.Ping()
if err != nil {
log.Print("error on db.Ping() => " ,err)
}
}
但我有以下问题:
2019/11/04 14:59:24 error on db.Ping() => SQL Error 4321 - only secure connections are allowed
我也试过这个:
hdbDsn = "hdb://user:password@hostname:port?encrypt=true"
但无法连接到 Hana 数据库。
有人可以帮助我吗?
纯 Go HANA SQL 客户端库很可能不支持加密(类似于纯 Python 客户端)。您应该使用官方 HANA go 客户端 (https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.04/en-US/0ffbe86c9d9f44338441829c6bee15e6.html) 并设置连接属性:
- 加密=真
- 验证证书=假
经过大量测试,我找到了这个姑息解决方案:
package main
import (
"crypto/tls"
"database/sql"
"github.com/SAP/go-hdb/driver"
_ "github.com/SAP/go-hdb/driver"
"log"
)
const (
HOST = "host"
PORT = ":port"
USERNAME = "user"
PASSWORD = "password"
)
func main() {
c := driver.NewBasicAuthConnector(
HOST+PORT,
USERNAME,
PASSWORD)
tlsConfig := tls.Config{
InsecureSkipVerify: false,
ServerName: HOST,
}
c.SetTLSConfig(&tlsConfig)
db := sql.OpenDB(c)
var id int
var name string
res := db.QueryRow("SELECT * FROM SCHEMA.TABLE LIMIT 1")
res.Scan(&id, &name)
log.Println("res ", id, name)
}
在 link SAP - Go (golang) Support 之后编写了以下代码:
package main
import (
"database/sql"
_ "github.com/SAP/go-hdb/driver"
"log"
)
const (
driverName = "hdb"
hdbDsn = "hdb://user:password@hostname:port"
)
func main() {
db, err := sql.Open(driverName, hdbDsn)
if err != nil {
log.Print("error on sql open => " ,err)
}
err = db.Ping()
if err != nil {
log.Print("error on db.Ping() => " ,err)
}
}
但我有以下问题:
2019/11/04 14:59:24 error on db.Ping() => SQL Error 4321 - only secure connections are allowed
我也试过这个:
hdbDsn = "hdb://user:password@hostname:port?encrypt=true"
但无法连接到 Hana 数据库。
有人可以帮助我吗?
纯 Go HANA SQL 客户端库很可能不支持加密(类似于纯 Python 客户端)。您应该使用官方 HANA go 客户端 (https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.04/en-US/0ffbe86c9d9f44338441829c6bee15e6.html) 并设置连接属性:
- 加密=真
- 验证证书=假
经过大量测试,我找到了这个姑息解决方案:
package main
import (
"crypto/tls"
"database/sql"
"github.com/SAP/go-hdb/driver"
_ "github.com/SAP/go-hdb/driver"
"log"
)
const (
HOST = "host"
PORT = ":port"
USERNAME = "user"
PASSWORD = "password"
)
func main() {
c := driver.NewBasicAuthConnector(
HOST+PORT,
USERNAME,
PASSWORD)
tlsConfig := tls.Config{
InsecureSkipVerify: false,
ServerName: HOST,
}
c.SetTLSConfig(&tlsConfig)
db := sql.OpenDB(c)
var id int
var name string
res := db.QueryRow("SELECT * FROM SCHEMA.TABLE LIMIT 1")
res.Scan(&id, &name)
log.Println("res ", id, name)
}