I am able to use unixodbc without any problem with my default user. But when I switch to another user, I get an error.
[centos# ~]$ odbcinst -q -s
[ODBC]
[Amazon Redshift DSN 32]
[centos# ~]$ su ruser
Password:
[ruser# centos]$ odbcinst -q -s
odbcinst: SQLGetPrivateProfileString failed with Unable to find component name.
Environment variables are set in both of the users:
AMAZONREDSHIFTODBCINI=/etc/amazon.redshiftodbc.ini
ODBCSYSINI=/usr/local/odbc
ODBCINI=/etc/odbc.ini
LD_LIBRARY_PATH=/usr/local/lib
LD_PRELOAD=/usr/local/lib/libodbcinst.so
Odbc configuration is as follows:
[ruser# centos]$ odbcinst -j
unixODBC 2.3.4
DRIVERS............: /usr/local/odbc /odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/odbc /odbc.ini
FILE DATA SOURCES..: /usr/local/odbc /ODBCDataSources
USER DATA SOURCES..: /etc/odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
By the way, I don't understand why there are spaces in the above paths. I don't know if there is a way to change them. Any ideas to solve this issue? Overall odbc configuration seems the same in both of the users.
I found the exact same issue on Centos, where I could use the default centos user to connect, but not any other users.
I was able to resolve the issue by copying the working user (or system) odbc.ini and odbcinst.ini files across into the home directory of the other user, like so (where I have renamed them to .odbc.ini and .odbcinst.ini respectively):
~/.odbc.ini
[MSSQLTest]
Driver = ODBC Driver 17 for SQL Server
Server = tcp:<ip of server>
~/.odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1
UsageCount=1
Finally, I just had to set the following environment variables inside my ~/.bashrc file, and I was able to connect.
export ODBCSYSINI="<full path to user folder, which would be the evaluated path of {echo ~}>"
export ODBCINSTINI=".odbcinst.ini"
export ODBCINI="<full path to user folder, which would be the evaluated path of {echo ~}>/.odbc.ini"
For some reason, I wasn't able to use ~ to reference the user folders, so I had to manually specify the full user path in the environment variables, and thus my complete .bashrc file is simply:
export ODBCSYSINI="/home/mitch"
export ODBCINSTINI=".odbcinst.ini"
export ODBCINI="/home/mitch/.odbc.ini"
With this setup, I could now run the following and connect successfully:
$ isql -v MSSQLTest <sql server username> <sql server password>
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
Related
I am trying to connect to a Microsoft SQL Server database from R studio.
I installed the unixODBC driver manager using homebrew:
brew install unixodbc
I then tried to install the freetds driver as recommended on https://db.rstudio.com/best-practices/drivers/
# SQL Server ODBC Drivers (Free TDS)
brew install freetds --with-unixodbc
I received the error:
Error: invalid option: --with-unixodbc
I found a source saying the option is no longer available because it is default now. Thus, I ran:
brew install freetds
In R Studio (and R) I then attempted to list the installed driver, but it was not found:
> odbc::odbcListDrivers()
[1] name attribute value
<0 rows> (or 0-length row.names)
Next I tried to install the Microsoft ODBC driver for SQL Server (macOS) according to https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15 and as recommended on https://db.rstudio.com/databases/microsoft-sql-server/
I ran:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools
To check that this driver was registered in an odbcinst.ini file I first ran:
odbcinst -j
with result:
unixODBC 2.3.9
DRIVERS............: /opt/homebrew/etc/odbcinst.ini
SYSTEM DATA SOURCES: /opt/homebrew/etc/odbc.ini
FILE DATA SOURCES..: /opt/homebrew/etc/ODBCDataSources
USER DATA SOURCES..: /Users/Gina/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
The driver was already registered in /opt/homebrew/etc/odbcinst.ini
view /opt/homebrew/etc/odbcinst.ini
file contents (note the freetds driver does not appear to be present):
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/homebrew/lib/libmsodbcsql.17.dylib
UsageCount=1
In Rstudio, I tried again to list the drivers and none were found:
> odbc::odbcListDrivers()
[1] name attribute value
<0 rows> (or 0-length row.names)
I have tried many more things, including:
copying the contents of /opt/homebrew/etc/odbcinst.ini to the user level file /Users/Gina/.odbcinst.ini
editing the /opt/homebrew/etc/odbc.ini file (which was previously empty) to include connection details (though I was planning to just specify these in the DBI::dbConnect command). New redacted file contents:
[ODBC Driver 17 for SQL Server]
Driver = ODBC Driver 17 for SQL Server
Servername = servername.net
Database = databasename
UserName = rstudioapi::askForPassword("Database user")
Password = rstudioapi::askForPassword("Database password")
Port = 1433
copying the contents of the /opt/homebrew/etc/odbc.ini to the user level file /Gina/.odbc.ini
setting an environmental variable:
export ODBCSYSINI=/opt/homebrew/etc
Note that when I run:
odbcinst -q -s
The driver is found:
[ODBC Driver 17 for SQL Server]
Thus, it appears that odbc::odbcListDrivers() should be able to find the driver. Any thoughts or suggestions would be very much appreciated! Thank you!
EDIT:
I also tried using the New Connection button and interestingly, my driver is listed there!
New Connection Window
However, when I click on it and click Test, I get an error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Data source name not found and no default driver specified
Driver Connection Window with Error
I get the same error when I try:
isql -v ODBC Driver 17 for SQL Server myusername mypassword
[IM002][unixODBC][Driver Manager]Data source name not found and no
default driver specified
EDIT 2:
I changed the Data Source Name (top line in odbc.ini file) to "SQLSever" and changed the Servername argument to Server (I did this in both the system level file and the user level file). Now when I run the below command it tries to connect (though hits a new error).
isql -v SQLServer myusername mypassword
[08001][unixODBC][Microsoft][ODBC Driver 17 for SQL Server]SSL
Provider: [OpenSSL library could not be loaded, make sure OpenSSL
1.0 or 1.1 is installed]
[08001][unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Client
unable to establish connection
[ISQL]ERROR: Could not SQLConnect
However, unfortunately, I still can not connect in R. I get the same errors as before.
Note that it appears that the isql command uses the system level files and RStudio uses the user level files. The files are identical in both places.
I read in a post on a similar issue that the M1 Macs have this problem but non-M1 Macs do not. Thus, I tried repeating the whole process on an older Macbook Pro and did not encounter the problem! odbc::odbcListDrivers() immediately listed the driver after installing the Microsoft ODBC driver for SQL Server (macOS). I did not need to edit or create any files.
With M1 Mac I was able to connect to SQL Server through terminal by changing the openssl folder to an older version. The driver installs openssl#3 (opt/homebrew/opt/openssl#3) but you actually need to use openssl#1.1 instead.
Here are the steps i followed in terminal:
brew install openssl#1.1
rm /opt/homebrew/opt/openssl
ln -s /opt/homebrew/Cellar/openssl#1.1/1.1.1l_1 /opt/homebrew/opt/openssl
This will create a symlink "openssl" and point it to the correct file (1.1.1l_1) inside the opt/homebrew/Cellar/openssl#1.1 folder.
Before creating the symlink verify the file name 1.1.1l_1 has not changed with a newer version in opt/homebrew/Cellar/openssl#1.1/1.1.1l_1
This solution worked for me:
Create two symlinks:
sudo mkdir -p /usr/local/etc
sudo ln -s /opt/homebrew/etc/odbc.ini /usr/local/etc/odbc.ini
sudo ln -s /opt/homebrew/etc/odbcinst.ini /usr/local/etc/odbcinst.ini
I am trying to use Flyway to set up a DB2 test/demo environment in a Docker container. I have an image of DB2 running in a docker container and now am trying to get flyway to create the database environment. I can connect to the DB2 docker container and create DB2 objects and load them with data, but am looking for a way for non-technical users to do this (i.e. clone a GitHub repo and issue a single docker run command).
The Flyway Docker site (https://github.com/flyway/flyway-docker) indicates that it supports the following volumes:
| Volume | Description |
|-------------------|--------------------------------------------------------|
| `/flyway/conf` | Directory containing a flyway.conf |
| `/flyway/drivers` | Directory containing the JDBC driver for your database |
| `/flyway/sql` | The SQL files that you want Flyway to use |
I created the conf, drivers, and sql directories. In the conf directory, I placed the file flyway.conf that contained my flyway Url, user name, and password:
flyway.url=jdbc:db2://localhost:50000/apidemo
flyway.user=DB2INST1
flyway.passord=mY%tEst%pAsSwOrD
In the drivers directory, I added the DB2 JDBC Type 4 drivers (e.g. db2jcc4.jar, db2jcc_license_cisuz.jar),
And in the sql directory I put in a simple table creation statement (file name: V1__make_temp_table.sql):
CREATE TABLE EDS.REFT_TEMP_DIM (
TEMP_ID INTEGER NOT NULL )
, TEMP_CD CHAR (8)
, TEMP_NM VARCHAR (255)
)
DATA CAPTURE NONE
COMPRESS NO;
Attempting to perform the docker run with the flyway/flyway image as described in the GitHub Readme.md, it is not recognizing the flyway.conf file, since it does not know the url, user, and password.
docker run --rm -v sql:/flyway/sql -v conf:/flyway/conf -v drivers:/flyway/drivers flyway/flyway migrate
Flyway Community Edition 6.5.5 by Redgate
ERROR: Unable to connect to the database. Configure the url, user and password!
I then put the url, user, and password inline and It could not find the JDBC driver.
docker run --rm -v sql:/flyway/sql -v drivers:/flyway/drivers flyway/flyway -url=jdbc:db2://localhost:50000/apidemo -user=DB2INST1 -password=mY%tEst%pAsSwOrD migrate
ERROR: Unable to instantiate JDBC driver: com.ibm.db2.jcc.DB2Driver => Check whether the jar file is present
Caused by: Unable to instantiate class com.ibm.db2.jcc.DB2Driver : com.ibm.db2.jcc.DB2Driver
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
Therefore, I believe it is the way that I am setting up the local file system or associating to local files with the flyway volumes that is causing the issue. Does anyone have an idea of what I am doing wrong?
You need to supply absolute paths to your volumes for docker to mount them.
Changing the relative paths to absolute paths fixed the volume mount issue.
docker run --rm \
-v /Users/steve/github-ibm/flyway-db-migration/sql:/flyway/sql \
-v /Users/steve/github-ibm/flyway-db-migration/conf:/flyway/conf \
-v /Users/steve/github-ibm/flyway-db-migration/drivers:/flyway/drivers \
flyway/flyway migrate
Trying to use sqlcmd from mssql-tools package (loosly following the docs here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7) and seeing error
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Data source name not found and no default driver specified.
even though I believe that both DSN and driver are specified (see below)
[airflow#airflowetl ~]$
[airflow#airflowetl ~]$
[airflow#airflowetl ~]$ # trying to connect to DB via DSN (-S option)
[airflow#airflowetl ~]$ /opt/mssql-tools/bin/sqlcmd -Q "select count(*) from MYTABLE" -D -S "MyMSSQLServer" -U "myuser" -P "mypass" -d mydb -W -h-1 -k
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Data source name not found and no default driver specified.
[airflow#airflowetl ~]$
[airflow#airflowetl ~]$
[airflow#airflowetl ~]$ # checking odbc config files
[airflow#airflowetl ~]# odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
[airflow#airflowetl ~]$ cat /etc/odbc.ini
[MyMSSQLServer]
Driver=ODBC Driver 17 for SQL Server
Description=My MS SQL Server
Trace=No
Server=172.18.1.23
[airflow#airflowetl ~]$ cat /etc/odbcinst.ini
[airflow#airflowetl ~]$ ls -lha /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.2.1
-rwxr-xr-x 1 root root 2.0M Sep 26 06:19 /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.2.1
Notice that /etc/odbcinst.ini is blank when (I think) it should corespond to Driver entries in the odbc.ini file. Should I just fill this in manually? Why does it not auto-fill in this case (as it has done on other machines where I have set up odbc)?
Not much experience with ODBC setup, so not sure what to make of this error. Anyone with more experience have any fuirther debugging tips or know how to fix?
Did you install the driver? Please have a look this link and follow the steps.
https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
Regards
xavy
I'm trying to set up an OBDC interface to two different MariaDB instances and I'm completely mystified by the fact that one works and the other doesn't.
One db ("platan") is running on a regular MariaDB installation on CentOS7 on 3306, whereas the other db ("tlex") is in a MariaDB instance inside a Docker container on the same OS and running on port 3301. I have to keep those two instances separate.
Both databases are reachable from the command line:
mysql -u mrtlex -pPASSWORD -h 127.0.0.1 -P3306 tlex
and
mysql -u platan -pPASSWORD -h 127.0.0.1 -P3301 platan
let me connect without a hitch.
I have the MariaDB driver defined in odbcinst.ini:
[MariaDB]
Description = MariaDB Connector/ODBC v.3.0
Driver64 = /usr/local/lib64/libmaodbc.so
And I have two data sources defined in odbc.ini:
[tlex]
Description = TLex dockerized
Driver = MariaDB
Database = tlex
Server = 127.0.0.1
Uid = mrtlex
Password = PASSWORD
Port = 3301
[platan]
Description = MariaDB localdb
Driver = MariaDB
Database = platan
Server = 127.0.0.1
Uid = platan
Password = PASSWORD
Port = 3306
odcbinst seems to recognize both datasources:
[root#CentOS-73-64-minimal ~]# odbcinst -q -s
[tlex]
[platan]
Yet I can actually connect only to platan and not the tlex datasource:
[root#CentOS-73-64-minimal ~]# iusql -v tlex
[unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLDriverConnect
[root#CentOS-73-64-minimal ~]# iusql -v platan
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
This doesn't make any sense to me. I can access both databases from the command line, both databases are set up the same way as ODBC datasources, both datasources as listed with odbcinst -q -s yet I can connect to only one of them through ODBC.
What could be the reason? How could I further troubleshoot this?
Many thanks in advance.
In order for a dockerized MariaDB to be accessible via ODBC, the container itself has to have unixODBC installed as well as the MariaDB ODBC driver and the data source file.
I'm trying to import a file into MariaDB on my WSL Subsystem on Windows, following this thread: https://stackoverflow.com/questions/17666249/how-to-import-an-sql-file-using-the-command-line-in-mysql
I have copied the .sql file to my home directory in WSL and hence my command looks like this:
$ mysql -u root -p sampledatabase < ~/databases/Datanmodell_init.sql
But I keep getting the following error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: YES)
What am I doing wrong?
merci A