I am new to Golang and I am trying to connect to Dremio using ODBC in Golang with Dremio host, port, username and password. The following code gives me error
2022/04/19 17:36:42 missing username and password
exit status 1
import (
"database/sql"
"fmt"
"gographqlservice/graph/model"
"log"
_ "github.com/pinpt/go-dremio/driver"
)
const (
host = "dremio.xyz.abc.com"
user = "user1"
password = "user_password"
port = 32010
)
func GetAsset(id string) (*model.Asset, error) {
drminfo := fmt.Sprintf("host=%s port=%d user=%s password=%s sslmode=disable",
host, port, user, password)
db, err := sql.Open("dremio", drminfo)
if err != nil {
log.Fatal("error occurred")
log.Fatal(err)
}
rows, err := db.Query("SELECT * FROM space.xyz.\"assets\" WHERE ASSET_ID = ?", id)
if err != nil {
log.Fatal(err)
}
var asset model.Asset
defer rows.Close()
for rows.Next() {
// some code goes here
}
err = rows.Err()
if err != nil {
log.Fatal(err)
}
defer db.Close()
return &asset, err
}
It looks like you are using driver code from "Pinpoint" that is documented here: https://pkg.go.dev/github.com/pinpt/go-dremio#section-readme
You can see their connection string should be in the following form:
Your code appears to be in the form:
To allow the Pinpoint code to parse this connection string and pull out the user and password, try the following instead:
The error message you're seeing comes from the following line in the Pinpoint code. In this case, it means they were not able to figure out the user name from the connection string provided. https://github.com/pinpt/go-dremio/blob/master/driver/driver.go#L187