I'm getting an "Invalid attribute value" when I try to connect to MSSQL from Linux.
My current /etc/odbcinst.ini file looks as follows:
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.1.so.0.1
Trace=yes
TraceFile=/home/mercury/Desktop/tracefile.txt
UsageCount=1
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2
UsageCount=1
My /etc/odbc.ini file looks like follows (information removed):
[TestServer]
Driver = ODBC Driver 17 for SQL Server
Server = $IP, $PORT
Database = $DATABASE
UserName = $Username
Password = $Password
If I run isql, I can connect with this command:
isql -v TestServer $Username $Password
Before I do the connection with nanodbc I print out the connection string that will be used which is:
DRIVER={ODBC Driver 17 for SQL Server};SERVER=$Server,$Port;DATABASE=$Database;Uid=$Username;Pwd=$Password
I then do: nanodbc::connection(connectionString); which is where I get the
[unixODBC][Driver Manager]Invalid attribute value
error message.
So after a REALLY long time this turned out to be an issue with Ubuntu 16.04. unixodbc on Ubuntu 16.04 reports its version wrong so when compiling nanodbc it uses the wrong version of unixodbc. To fix this, recompile nanodbc with this cmake flag on: For example:
mkdir build
cd build && cmake .. -DNANODBC_ODBC_VERSION=SQL_OV_ODBC3
This fixed the issue for me. For future reference, this ticket was the answer: https://github.com/lexicalunit/nanodbc/issues/149