alexbrainman / odbc

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

SQLDriverConnect: {IM002} [unixODBC][Driver Manager]Data source name not found, and no default driver specified #152

Closed bsuligoj closed 3 years ago

bsuligoj commented 3 years ago

Hi guys, I came across this issue and I have no idea how to proceed.

The driver I am using is for Apache Drill (maprdrill-1.5.1.1002-1.el7.x86_64.rpm), and the OS I am using is CentOS 7 (vagrant).

The driver works just fine with Python, also isql can see and use datasource without any problems.

My code looks fairly simple:

package main

import (
    "database/sql"

    _ "github.com/alexbrainman/odbc"
    log "github.com/sirupsen/logrus"
)

func main() {
    // Open Connection. Provide DSN, Username and Password
    db, err := sql.Open("odbc", "DSN=local")
    if err != nil {
        log.Fatal("could not connect to database ", err)
    } else {
        log.Println("connection successful")
    }

    query := "SELECT NOW()"
    // Provide the Query to execute
    log.Debug("running query: \n", query)
    rows, err := db.Query(query)
    if err != nil {
        log.Fatal("there was error executing query: ", err)
    }
    defer rows.Close()

    var result interface{}
    for rows.Next() {
        err = rows.Scan(
            &result,
        )
        if err != nil {
            log.Error("could not parse result ", err)
        }

        log.Info(result)
    }
}

My /etc/odbc.ini looks like this:

[ODBC]
Trace=no

[ODBC Data Sources]
MapR Drill 32-bit=MapR Drill ODBC Driver 32-bit
MapR Drill 64-bit=MapR Drill ODBC Driver 64-bit

[local]
# This key is not necessary and is only to give a description of the data source.
Description=MapR Drill ODBC Driver (64-bit) DSN
# Driver: The location where the ODBC driver is installed to.
Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so
# The DriverUnicodeEncoding setting is only used for SimbaDM
# When set to 1, SimbaDM runs in UTF-16 mode.
# When set to 2, SimbaDM runs in UTF-8 mode.
# DriverUnicodeEncoding=2
# Values for ConnectionType, AdvancedProperties, Catalog, Schema should be set here.
# If ConnectionType is Direct, include Host and Port. If ConnectionType is ZooKeeper, include ZKQuorum and ZKClusterID
# They can also be specified on the connection string.
# AuthenticationType: No authentication; Username; Plain; Kerberos; MapRSASL;
ConnectionType=Direct
HOST=localhost
PORT=31010
# ZKQuorum=[Zookeeper Quorum]
# ZKClusterID=[Cluster ID]
AuthenticationType=No Authentication
# UID=[USERNAME]
# PWD=[PASSWORD]
DelegationUID=
KrbServiceName=mapr
KrbServiceHost=
krbSpnConfigurationsRequired=1
AdvancedProperties=CastAnyToVarchar=true;HandshakeTimeout=5;QueryTimeout=300;TimestampTZDisplayTimezone=utc;ExcludedSchemas=sys,INFORMATION_SCHEMA;NumberOfPrefetchBuffers=5;
Catalog=DRILL
Schema=
SSL=0
DisableHostVerification=0
DisableCertificateVerification=0
TrustedCerts=/opt/mapr/drill/lib/64/cacerts.pem
UseSystemTrustStore=0
# The key, "UseExactTLSProtocolVersion", toggles between "Min_TLS" or "TLSProtocol".
# UseExactTLSProtocolVersion=1 indicates that the driver should use the exact TLS Protocol version to communicate with the drillbit.
# UseExactTLSProtocolVersion=0 indicates that the driver should use the minimum TLS Protocol version to communicate with the drillbit.
UseExactTLSProtocolVersion=0
Min_TLS=

My /etc/odbcinst.ini looks like this:

[ODBC Drivers]
MapR Drill ODBC Driver 32-bit=Installed
MapR Drill ODBC Driver 64-bit=Installed

[MapR Drill ODBC Driver 32-bit]
Description=MapR Drill ODBC Driver(32-bit)
Driver=/opt/mapr/drill/lib/32/libdrillodbc_sb32.so

[MapR Drill ODBC Driver 64-bit]
Description=MapR Drill ODBC Driver(64-bit)
Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so

What I've tried so far:

Any help would be appreciated.

EDIT: I've tested the same code with the same configuration on Debian 10 and it works, both done on completely fresh instances in Vagrant.

alexbrainman commented 3 years ago

@Shark4109

This sounds like your driver configuration issue.

I do not know how to configure every driver available. You should ask people who built your driver.

Sorry, but I cannot help you.

Alex

bsuligoj commented 3 years ago

@alexbrainman

You are correct, it was the driver issue. For some reason The driver didn't care about the Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so part. When I put this into code e.g. db, err := sql.Open("odbc", "DSN=local;Driver=/opt/mapr/drill/lib/64/libdrillodbc_sb64.so") it worked.

Thanks for help anyway, and great work on ODBC imlepmentation 👍 .