odbc.ini file configuration for when using key value pair (not PWD) - odbc

Reading documentation here.
I would like to use an odbc connection with Snowflake. I'm already able to get this working by adding .odbc.ini to my home directory with a configuration that looks similar to this:
[snowflake]
Description=SnowflakeDB
Driver=SnowflakeDSIIDriver
Locale=en-US
SERVER=ourco.us-east-1.snowflakecomputing.com
PORT=443
SSL=on
ACCOUNT=ourco.us-east-1
UID=MY_NAME
PWD=$MyPassword
This works. With this config, I'm able to create a connection and query our database.
However I would like to use odbc with keys instead of my password. Followed guide here on creating keys and added them within SF interface.
I then updated my odbc.ini file:
[snowflake]
Description=SnowflakeDB
Driver=SnowflakeDSIIDriver
Locale=en-US
SERVER=ourco.us-east-1.snowflakecomputing.com
PORT=443
SSL=on
UID=MY_NAME
ACCOUNT=ourco.us-east-1
PRIV_KEY_FILE=/home/rstudio-blah/keys/rsa_key.p8 # this is where I stored the key
SNOWSQL_PRIVATE_KEY_PASSPHRASE=potatoes{ # not my real pwd
When attempting to connect with this set up I got error message:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Snowflake][DSI] (20032) Required setting 'PWD' is not present in the connection settings.
I tried adding PWD= just trying to trick it with a null value but then got:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Snowflake][Snowflake] (31)
Password not found.
I then tried adding AUTHENTICATOR=SNOWFLAKE_JWT which gave error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Snowflake][Snowflake] (44)
Error finalize setting: Marshaling private key failed.
How can I connect via odbc using a key value pair as opposed to a PWD?

Related

Error connecting to Oracle Database via odbc in RStudio. Works smoothly when starting from Terminal

I am trying to establish a connection to an Oracle Database in RStudio (Version 2022.07.1 Build 554. Running on SUSE SLE15, SP4).
The connection should by established via an ldap-Server. Its address is in my ldap.ora file which is in /opt/instantclient_19/network/admin.
The code isql my_datasource does establish the connection.
Putting the following code in an R-file an executing via Rscript establishes the connection.
dbConnect(
odbc::odbc(),
dsn = "my_datasource",
UID = "***",
PWD = "***"
)
Trying to source the same script in RStudio (or RStudio Server) throws an error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the connect identifier specified
There should be a .Renviron file in your home directory. If not, you'll want to create a text file and save it with .Renviron as the filename. In that file, you'll want to define a path for the ODBCINI environmental variable to an ".odbc.ini" or "odbc.ini" file. For example,
ODBCINI = ~/.odbc.ini
The file in this path should list all DSNs you can use to make a connection. For more information, please see https://solutions.rstudio.com/db/best-practices/drivers/.

ODBC Issue in Red Hat linux release 6.9:

ODBC Issue
The database reported an error: [unixODBC][Driver Manager]Data Source name not found, and no default driver specified
As shown as below, QT application trying to connect a database file of type DBF (.dbf), when we try to execute the application we got the above error.
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QODBC");
QString str("DRIVER={Microsoft dBase Driver (*.dbf)}; DBQ=/path/to/dbf/files");
db.setDatabaseName(str);
if(db.open())
{
...
}
else
{
...// Failure
}
Referred the link (https://www.easysoft.com/support/kb/kb01039.html) and followed the below steps:
The configuration files odbc.ini and odbcinst.ini are present with the appropriate content.
Exported the variables ODBCSYSINI, ODBCINSTINI and ODBCINI with /etc/odbc.ini, /etc/odbcinst.ini and /home/user/.odbc.ini
From the same shell where we have exported the variables, tried to execute the application however encountered with the error "The database reported an error: [unixODBC][Driver Manager]Data Source name not found, and no default driver specified
Please find the content of the odbc.ini and odbcinst.ini
odbc.ini file:
[ODBC Data Sources]
TestODBC=MyODBCDriver
[TestODBC]
Driver=path/to/driver file
DataDirectory=path/to/where my dbf files resides
[Default]
Driver=path/to/driverfile
DataDirectory=path/to/where my dbf files resides
odbcinst.ini file:
[ODBC Drivers]
MyODBCDRIVER=Installed
[MyODBCDriver]
Description=ODBC Driver
Driver=/path/to Driver file
[ODBC]
Trace = Yes
Please provide any suggestion or solution to resolve the issue

Unable to Connect to Database using Custom Connection String with ODBC.jl

I'm having trouble connecting to a database with the ODBC.jl package. I can't tell if the problem is with my setup (more likely) or the package. The problem is that ODBC.jl can't seem to locate the correct ODBC driver.
> using ODBC
> ODBC.listdrivers()
/path/to/generic/odbc/
But I need to use a different driver than the one picked up from above.
I'm trying to use a custom connection string as follows:
>ODBC.DSN("DRIVER=path/to/driver/i/want;SERVER=myserver;USER=myuser;PASSWORD=mypass;DATABASE=somedb;")
which returns this:
[ODBC] IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ERROR: ODBC.ODBCError("ODBC.API.SQLDriverConnect(dbc,window_handle,conn_string,out_conn.ptr,BUFLEN,out_buff,driver_prompt) failed; return code: -1 => SQL_ERROR ")
My understanding is that I should be able to specify the driver as done above, but this does not give the desired connection.
I have .odbc.ini and .odbcinist.ini files set-up in my home directory, which I believe are working correctly. I'm on a Suse enterprise distro. When connecting via isql i have no problems.
Any help is appreciated.

Connecting to Vertica database via pyodbc without odbc.ini on RHEL6

I do not have the permission to edit the system-wide odbc.ini file, therefore I am searching for alternative ways to specify connection parameters towards Vertica.
I have unpacked the needed libraries to a certain location, and am attempting to create a connection string from my "custom" config file.
Is it possible to explicitly specify the path to the driver (and any other necessary parameters) when using pyodbc.connect?
Example intention (fails with the error below):
conn = pyodbc.connect("DRIVER=path/to/libverticaodbc.so;...")
Error:
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
Alternatively, is there another option to use odbc.ini files other than the ones at /etc/, e.g. through setting an environment variable?
I recommend to avoid the use of ODBC driver to connect to Vertica .
Vertica release native driver for python , see attach full details and examples :
https://github.com/uber/vertica-python
I hope you will find it us-full
Thanks
You can put a file called .odbc.ini in your home directory which will be for user specific ODBC settings.
http://www.unixodbc.org/odbcinst.html

How can I connect to a sqlite3 db using pyodbc and unixODBC?

I can't figure out how to connect to a sqlite db using pyodbc. I have a DSN set up and can connect to it via isql without problems.
isql -v TEST
works like a charm, However
import pyodbc
pyodbc.connect('DSN=TEST')
Gives the following error message:
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')
I also tried a great amount of permutations of the connection strings in the examples at https://code.google.com/p/pyodbc/wiki/GettingStarted to no avail.
pyodbc.dataSources()
Does list the dsn I'm trying to connect to with the value holding the path to libsqlite3odbc.so
I assume I am missing something obvious, but I can't figure out what...
EDIT: Using unixODBC 2.3.0, python 2.7.1, sqliteodbc 0.88 and pyodbc 2.1.8
EDIT: The reason I want to use pyodbc is for portability to Windows and MS Access
Just to check what is being passed to the driver manager, turn on ODBC tracing, in your odbcinst,ini file add
[ODBC]
Trace = Yes
TraceFile = /tmp/sql.log
Then run the app again and see what is being passed to the SQLConnect or SQLDriverConnect call.

Resources