3

following the link SAP - Go (golang) Support a made the code below:

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)
    }

}

but I have the following problem:

2019/11/04 14:59:24 error on db.Ping() => SQL Error 4321 - only secure connections are allowed

I, tried too this:

hdbDsn     = "hdb://user:password@hostname:port?encrypt=true"

but is not possible connect to Hana database.

Someone could help me?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
pedrualves
  • 93
  • 9
  • @Flimzy how to do this? Are you know Hana Database ? Because SAP Hana Database is something differente from others databases =/ – pedrualves Nov 04 '19 at 17:35
  • 1
    Are you actually using `"hdb://user:password@hostname:port"`, or are you substituting in your own username, password, host, and port? – Gavin Nov 04 '19 at 19:04
  • I have substituted host,user,password and port with my real values. Values wich I use to connect using Dbeaver. – pedrualves Nov 04 '19 at 20:57

2 Answers2

1

The pure Go HANA SQL client library very likely does not support encryption (similar to the pure Python client). You should use the official HANA go client (https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.04/en-US/0ffbe86c9d9f44338441829c6bee15e6.html) and set connection properties:

  • encrypt=true
  • validateCertificate=false
kai-morich
  • 427
  • 2
  • 7
1

after a lot of tests I found this palliative solution:

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)

}
pedrualves
  • 93
  • 9