alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
352 stars 140 forks source link

Not able to connect to teradata using odbc #145

Open rafaeldihl opened 4 years ago

rafaeldihl commented 4 years ago

Hi Alex, I'm trying to use your odbc driver to connect to teradata but it is not working. I have configured the odbc driver correctly and based on the command below you can see it works:

[vagrant@localhost vagrant]$ /opt/teradata/client/16.20/bin/tdxodbc64 -c SQLDriverConnect -C "DSN=teradatatest" -t

Connecting with SQLDriverConnect("DSN=teradatatest")...

.....ODBC connection successful.

ODBC version = -03.52.0000- DBMS name = -Teradata- DBMS version = -16.20.3226 16.20.32.26- Driver name = -tdataodbc_sb64.so- Driver version = -16.20.00.098- Driver ODBC version = -03.52-

ODBC connection closed.

Here is the driver I'm using https://downloads.teradata.com/download/connectivity/odbc-driver/linux

See below the piece of code that is not working:

package main

import (
    "database/sql"
    "fmt"
    "log"

    _ "github.com/alexbrainman/odbc"
)

func main() {
    db, err := sql.Open("odbc",
        "DSN=teradatatest")
    if err != nil {
        log.Fatal(err)
    }

    if err := db.Ping(); err != nil {
        log.Println(fmt.Errorf("create connection: pinging database: %w", err))
    }
    defer db.Close()
}

It is returning the error below:

2020/07/02 18:13:18 create connection: pinging database: SQLSetEnvUIntPtrAttr: {奈㤰2} 䑛瑡䑡物捥嵴佛䉄⁃楬嵢传瑰潩祴数 漠瑵漠⁦慲杮e 2020/07/02 18:13:18 SQLSetEnvUIntPtrAttr: {奈㤰2} 䑛瑡䑡物捥嵴佛䉄⁃楬嵢传瑰潩祴数漠瑵漠⁦慲杮e

Looks like is not finding the DSN connection. I tested it in a windows machine too and had the same:

2020/07/02 13:35:46 create connection: pinging database: SQLDriverConnect: {IM002} [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 2020/07/02 13:35:46 SQLDriverConnect: {IM002} [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Do you have any idea to help me?

Thanks! Rafael Dihl

alexbrainman commented 4 years ago

"DSN=teradatatest"

I think for this to work, you have to use ODBC manager to create DSN called teradatatest. I suspect you have not done that, that is why your program cannot find it.

I suggest you use proper connection string with all connection parameters in it, not just DSN. This way your program will work regardless of ODBC manager config.

I have never used Teradata, but, just googling, I can see

https://www.simba.com/products/Teradata/doc/ODBC_InstallGuide/mac/content/odbc/td/strings.htm

I hope it helps.

Alex

rafaeldihl commented 4 years ago

Hi Alex,

Thanks for replying to my issue. After several attempts at running queries with this library I learned that I had to use for_issue_88 branch and comment these lines https://github.com/alexbrainman/odbc/blob/for_issue_88/driver.go#L43-L54. The reason I had to comment the lines is in the teradata odbc documentation: **** Note: Currently, Data Direct Driver Manager does not support Connection Pooling feature. I did not dig too much to see the difference between the for_issue_88 and master branch but that was the way I was able to make it work. Thanks! Rafael Dihl

alexbrainman commented 4 years ago

I learned that I had to use for_issue_88 branch ...

This branch is for ASCII (no UTF16) only version. I don't see how it helps you. Unless you have another problem / configuration issue.

... and comment these lines https://github.com/alexbrainman/odbc/blob/for_issue_88/driver.go#L43-L54. The reason I had to comment the lines is in the teradata odbc documentation: **** Note: Currently, Data Direct Driver Manager does not support Connection Pooling feature.

Yes. That might help. You also might try

https://github.com/alexbrainman/odbc/pull/143

Anyway. I am glad you found a solution.

Alex