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
Related
I tried to connect using isql command (Both are AWS EC2)
# isql -v WebDB
[S1000][unixODBC][MySQL][ODBC 8.0(w) Driver]Can't connect to MySQL server on 'ip:3306' (110)
[ISQL]ERROR: Could not SQLConnect
But I can able connect manually
~**]# mysql -h ip -u useranme -p $pwd**
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 304
Server version: 8.0.29 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
I tried to restart opensips that need to connect remote mysql8
/usr/local/sbin/opensips[2905]: ERROR:db_mysql:db_mysql_connect: driver error(2003): Can't connect to MySQL server on 'ip'
/usr/local/sbin/opensips[2905]: ERROR:db_mysql:db_mysql_new_connection: initial connect failed
/usr/local/sbin/opensips[2905]: ERROR:core:db_do_init: could not add connection to the pool
[2905]: ERROR:dialog:init_dlg_db: unable to connect to the database
/usr/local/sbin/opensips[2905]: ERROR:dialog:mod_init: failed to initialize the DB support
I'm trying to connect to locahost sql server but all the time I receive error:
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Loggin faield for user 'user'. QODBC3: Unable to connect;
I'm using Qt 5.4 on ubuntu.
Connection string:
QString connectionString = QString(("DRIVER=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.7.so.2.1;SERVER=localhost;DATABASE=FightClubDB;UID=kudryavii;PWD=Pass;"));
QSqlDatabase db{QSqlDatabase::addDatabase("QODBC", connectionId)};
db.setDatabaseName(connectionString);
return connectionId;
If you installed mssql-server via this article: https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15
then to connect to sql server you will have to use "SA" username not you account name...
I couldn't access to MySQL since yesterday.
> mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I've tried several things to fix, but don't have any clue yet.
MacOS Mojave (10.14.3)
Django
First Try
❯ find / -name mysql.sock
find: /usr/sbin/authserver: Permission denied
find: /usr/local/var/mysql: Permission denied
….
❯ mysql -u root -p mysql S/var/local/var/mysql/mysql.sock
mysql Ver 8.0.19 for osx10.14 on x86_64 (Homebrew) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
I could see some messages, but can not access to MySQL.
Second try
I found mysql.sock file in "/var/mysql/mysql.sock"
So I edited my.cnf file, but it didn't work.
❯ vi /usr/local/etc/my.cnf
# my.cnt
[client]
socket = /var/mysql/mysql.sock
[mysqld]
socket = /var/mysql/mysql.sock
❯ ln -s /tmp/mysql.sock /var/mysql/mysql.sock
ln: /var/mysql/mysql.sock: File exists
And there are other informations to try to fix.
> ❯ ls -l /tmp/mysql.sock
lrwxr-xr-x 1 seungholee wheel 31 8 30 18:45 /tmp/mysql.sock -> /usr/local/bin/mysql/mysql.sock
I have qt open source 5.12 and ubuntu 18.04. How do I connect to oracle 12c via ODBC?
I tried:
db = new QSqlDatabase(QSqlDatabase::addDatabase("QODBC"));
db->setPort(1234);
db->setDatabaseName("DRIVER={ODBC Driver 17 for SQL Server};"
"SERVER=localhost;"
"DATABASE=OraDoc;"
"Trusted_Connection=yes;");
db->setPassword("MyPasswd");
db->setUserName("system");
if(db->open()) qDebug() << "cool";
else qDebug() << db->lastError().text();
Writes:
"[Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
[Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2749
[Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. QODBC3: Unable to connect"
Revised Answer:
Steps to configure and test ODBC connectivity to an Oracle 12.2 database in Qt Open Source 5.12 on Ubuntu 18.04:
1) Install pre-requisites (if they aren't already installed).
sudo apt-get install build-essential libaio1
2) Install ODBC Driver Manager (unixODBC).
### Install packages
sudo apt-get install unixodbc unixodbc-dev
### Verify unixODBC installation
/usr/bin/odbcinst -j
# Expected output:
unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/<logged-in-user>/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
3) Install Oracle ODBC driver.
### Download files below from
### https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
instantclient-basic-linux.x64-12.2.0.1.0.zip
instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
### Unzip files to /opt/oracle
sudo unzip instantclient-basic-linux.x64-12.2.0.1.0.zip -d /opt/oracle
sudo unzip instantclient-odbc-linux.x64-12.2.0.1.0-2.zip -d /opt/oracle
4) Create tnsnames.ora file and add your database connection to it.
### File: /opt/oracle/instantclient_12_2/network/admin/tnsnames.ora
oradbconn =
(
DESCRIPTION =
(
ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = oradbserver.acme.com)
(PORT = 1521)
)
)
(
CONNECT_DATA = (SERVICE_NAME = oradb.acme.com)
)
)
5) Run odbc_update_ini.sh, which creates/updates the unixODBC configuration needed to register the Oracle ODBC driver with unixODBC and partially configure an Oracle ODBC data source.
cd /opt/oracle/instantclient_12_2
sudo ./odbc_update_ini.sh /
# This error can be ignored:
# *** ODBCINI environment variable not set,defaulting it to HOME directory!
Expected contents of unixODBC config files after running odbc_update_ini.sh:
### /etc/odbcinst.ini (Tells unixODBC where to find Oracle ODBC driver)
[Oracle 12c ODBC driver]
Description = Oracle ODBC driver for Oracle 12c
Driver = /opt/oracle/instantclient_12_2/libsqora.so.12.1
Setup =
FileUsage =
CPTimeout =
CPReuse =
### ~/.odbc.ini (Partially-configured Oracle ODBC Data Source)
[OracleODBC-12c]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
.
.
.
6) "Chown" ~/.odbc.ini to the uid/gid of the currently-logged in user. This file is initially created as root:root. If the ownership is not changed, database connections through the ODBC driver may fail.
sudo chown $(id -u):$(id -g) ~/.odbc.ini
7) Complete the data source configuration by adding/updating the ~/odbc.ini parameters shown below.
### ~/.odbc.ini
ServerName = oradbconn ### Should reference the connection in the tnsnames.ora file
UserID = oradb_user ### User name for your Oracle database connection
Password = oradb_password ### Password for username above
9) Update .bash_profile with Oracle environment variables and source the file.
### ~/.bash_profile
export TNS_ADMIN=/opt/oracle/instantclient_12_2/network/admin
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
### Source the file
. ~/.bash_profile
10) Verify connection to Oracle ODBC data source.
isql -v OracleODBC-12c
Expected output:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
11) Create program to test ODBC connectivity to Oracle.
your-project.pro:
.
.
QT += sql ### Add this to make SQL libraries available
main.cpp:
#include <iostream>
#include <QCoreApplication>
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
int main( int argc, char *argv[] )
{
QCoreApplication a(argc, argv);
// "OracleODBC-12c" is the data source configured in ~/.odbc.ini
QSqlDatabase db = QSqlDatabase::addDatabase( "QODBC3", "OracleODBC-12c" );
if(db.open())
qDebug() << "Opened db connection!";
else
qDebug() << db.lastError().text();
QSqlQuery query(db);
// Example query selects a few table names from the system catalog
query.exec("SELECT table_name FROM all_tables WHERE owner = 'SYS' and ROWNUM <= 3");
while (query.next()) {
QString table_name = query.value(0).toString();
qDebug() << table_name;
}
return a.exec();
}
Expected output (table names may vary):
Opened db connection!
"DUAL"
"SYSTEM_PRIVILEGE_MAP"
"TABLE_PRIVILEGE_MAP"
Above steps were verified on OS / Qt version below:
$ uname -a
Linux ubuntu 4.18.0-25-generic #26~18.04.1-Ubuntu SMP Thu Jun 27 07:28:31 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ ./qmake -v | grep Qt
Using Qt version 5.12.4 in /opt/Qt/5.12.4/gcc_64/lib
Original Answer:
It looks like you're trying to use an ODBC driver for SQL Server to connect to Oracle, which doesn't make sense to me.
db->setDatabaseName("DRIVER={ODBC Driver 17 for SQL Server};"
The QT documentation states:
Note: You should use the native driver, if it is available, instead of
the ODBC driver. ODBC support can be used as a fallback for compliant
databases if no native driver is available.
The information about building with the native Oracle OCI driver is here
You can download the Oracle instant client that contains the OCI driver from here. According to the QT docs, you'll need Instant Client Package - Basic" and "Instant Client Package - SDK". If you still want to use ODBC, then you could try downloading Oracle's "ODBC Package - Additional libraries for enabling ODBC applications" on the instant client download page. For all of these downloads, make sure that you get the client version corresponding to your database.
Recieving this error when connecting to MSSQL server
My linux machines details:-
Distributor ID: Ubuntu
Description: Ubuntu 14.04.2 LTS
Release: 14.04
MSSQL Server DB details:
version : 2012
Error:
django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
Python2.7
Driver: pyodbc == 3.0.10
django-pyodbc-azure == 1.8.3.0 django-mssql == 1.6.1 django >= 1.8.3
First, make sure you have the required packages installed (it looks like you may):
# Install pre-requesite packages
sudo apt-get install unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc
Then, make sure you have /etc/freetds/freetds.conf configured properly:
[global]
# TDS protocol version, use:
# 7.3 for SQL Server 2008 or greater (tested through 2014)
# 7.2 for SQL Server 2005
# 7.1 for SQL Server 2000
# 7.0 for SQL Server 7
tds version = 7.2
port = 1433
text size = 64512
# A typical Microsoft server
[dbserverdsn]
host = dbserver.domain.com
port = 1433
tds version = 7.2
Next, make sure you have unixODBC talking correctly through FreeTDS in /etc/odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Finally, make sure /etc/odbc.ini sees the FreeTDS data source you created:
[dbserverdsn]
Driver = FreeTDS
Server = dbserver.domain.com
Port = 1433
TDS_Version = 7.2
If you have issues along the way, please try testing with the 'tsql' and 'isql' command line utilities and post any errors you receive. Hopefully, this works.
If the problem is with Django's configuration, please post your Django DATABASES settings for review.