Trying to connect Sybase db using golang, but getting following error : netlib: unexpected EOF while reading message

49 views Asked by At

I am using one of the golang sybase driver "github.com/thda/tds" to connect sybase but not sure what is wrong with it, connection is happening with perl code but golang throwing error when trying to ping the connection :

netlib: unexpected EOF while reading message

my password having combination of special characters as well like "#" and "|", I am sure this might be the issue also I have code snippet here, kindly need any help to overcome this issue.

import (
    "database/sql"
       _ "github.com/thda/tds"
)

func getConn(cred map[string]string) (c *sql.DB) {
    Name := cred["NAME"]
    Pass := cred["PASS"] // 6#A(co&k|31V
    Server := cred["SERVER"]
    User := cred["USER"]
    Port := cred["PORT"]
    dbConn := fmt.Sprintf("dbname=%s host=%s port=%s user=%s password=%s", Name, Server, Port, User, Pass)
    cnxStr := "tds://" + url.QueryEscape(User) + ":" + url.QueryEscape(Pass) + "@" + Server + ":" + Port + "/" + Name + "?charset=utf8"
    conn, err := sql.Open("tds", cnxStr)
    if err != nil {
        fmt.Println("Open Connection failed..", err)
        panic(err)
    }
    conn.SetConnMaxLifetime(time.Minute * 4)
    conn.SetMaxIdleConns(0)
    defer conn.Close()
    if err := conn.Ping(); err != nil {
        log.Println("sql.Ping failed:", err.Error())
        return nil
    }

    return conn

}

sql.Ping failed: netlib: unexpected EOF while reading message

As i'm escaping the password to parse special characters withing it, but still it's not working, can you help me here to figure out what's wrong in this.your text

0

There are 0 answers