Qt ODBC - Unable to error - database

I'm trying to open MS Access db file with QT in Linux.
So, I have installed odbc plugin for qt:
sudo apt-get install libqt4-sql-odbc
Now there are 2 files qt4/plugins/sqldrivers directory: libqodbc.so & libqsqlite.so
So, I try to use ODBC plugin in my project. There is connection function:
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=/home/user/personal_base.mdb");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"), db.lastError().text());
return false;
}
return true;
}
But application dislpays error:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unale to connect
How should I fix it?

The call to setDatabaseName ends up in the ODBC function SQLDriverConnect. SQLDriverConnect defines a number of attributes you can set to declare which ODBC driver you are using and how to use it e.g., DRIVER. You told the unixODBC driver manager to load the driver "Microsoft Access Driver (*.mdb, *.accdb)" and it could not find that driver.
In unixODBC, drivers are usually defined in the odbcinst.ini file which you can usually find with the command "odbcinst -j". You'll find this article useful.
It is highly unlikely you have a Microsoft Access driver named as you've shown as this is usually the name of the MS Access driver which is only available on Windows.
To my knowledge there are only 2 ways to access MS Access DB directly from Linux using ODBC 1) mdbtools (which is old and incomplete but free) 2) Easysoft MS Access ODBC Driver which is a complete ODBC Driver but not free.

I had The same Problem with my project except that I'm using Windows. I think that this will help you:
Just change Your Driver into this Code(taken from QT Website):
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");

Related

i can't connect to Azure database in QT

My database is on an Azure server. And I'm trying to connect to it via an ODBC driver (by the way, I tried to install it manually, but I couldn't get it. They say it's built in). I get the following error: "Data source not found and no default ODBC driver specified: Unable to connect"
dataBaseKnowFood = QSqlDatabase::addDatabase("QODBC");
QString connectString = QStringLiteral("myconnectionstring");
dataBaseKnowFood.setDatabaseName(connectString);
dataBaseKnowFood.setPassword("dgf");
dataBaseKnowFood.setUserName("gidgfsg");
if (!dataBaseKnowFood.open())
{
QMessageBox::critical(this, "Programm", dataBaseKnowFood.lastError().text());
}
Problem solved. It was required to update this driver and indicate the version of the updated driver in the connection string.

Cannot create linked server - "Data source name not found" error - SQL Server Management Studio

I need to setup a linked server between SQL Server and IBM i, using ODBC driver (iSeries Access ODBC driver for Windows). I've been trying using sp_addlinkedserver, and using the assistant (following this tutorial), but none of that work.
EXEC master.dbo.sp_addlinkedserver #server = 'MYODBC',
#srvproduct='AS400',
#provider='MSDASQL',
#datasrc='MYODBC';
The error I get is "Data source name not found and no default driver specified (Error: 7303)."
Any suggestions?
Thanks in advance
Try following:
Verify if the DSN Name (MYODBC) exists, especially in ODBC Data Sources (64-bit), if exists re-create it using ODBC Data Sources (64-bit)
Re-install ODBC Drivers, and restart the system

R and SQL Server using Actual driver for Mac OS

I'm trying to connect RStudio on MacOS 10.12 to a SQL Server instance out on the network.
I tried installing RODBC via install.packages("RODBC"). This failed with the error:
configure: error: "ODBC headers sql.h and sqlext.h not found"
I understand Mac OS and RStudio use iODBC, but those headers are part of unixODBC, so I installed that via brew install unixODBC. That solved the RODBC install at least, and now I'm able to load that library successfully in RStudio via library(RODBC).
Next I installed ODBC Manager from http://odbcmanager.net and the Actual SQL Server driver from Actual Technologies. I was then able to setup a DSN pointing at my local SQL Server, which looks like this in /Library/ODBC/odbc.conf:
[ODBC Data Sources]
sqlbox = Actual SQL Server
[sqlbox]
Driver = /Library/ODBC/Actual SQL Server.bundle/Contents/MacOS/atsqlsrv.so
Description = SQLBox
Server = sqlbox.mydomain.com
UserID = myuser
UseKeychain = Yes
ServerName = sqlbox
host = sqlbox.mydomain.com
client charset = UTF-8
Now when I request a connection in R via conn<-odbcDriverConnect("sqlbox") I get this error:
Warning messages:
1: In odbcDriverConnect("sqlbox") :
[RODBC] ERROR: state S1092, code 0, message [Actual][SQL Server] Invalid option
2: In odbcDriverConnect("sqlbox") : ODBC connection failed
Obviously it is finding the DSN, and loading (or at least finding) the Actual driver, but something is still off. The ODBC Manager tool does not have a Test button to validate a connection, so I can't try that. Is there another tool which would give better feedback on why the connection is failing? What am I missing?
Removing the system DSN and recreating it as a user DSN (in ~/Library/ODBC/odbc.ini) seems to have solved it. I'm now able to connect and pull SQL Server data from R.

Connect to Ms SQL with RODBC without dsn

I'm trying to set up a connection from ubuntu to mssql server with the RODBC package.
I did make it work with RJDBC but read the speed might be much slower than ODBC so I wanted to test it.
I don't have a dsn available, ip port databasename usr pwd is all the information I can use.
The code used with RJDBC which works is:
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver",
"/media/sqljdbc4.jar")
RJDBC::dbConnect(drv, 'jdbc:sqlserver://ip:port;databaseName=databasename', 'usr', 'pwd')
Tried alot around browsing different syntaxes but could not make it work.
RODBC::odbcDriverConnect('driver={SQL Server};server=ip:port;database=databasename;uid=usr;pwd=pwd)
Gives me the error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
Do I need to download drivers to the ubuntu machine? Thought they were included with the package.
The RODBC package doesn't include drivers. That would be unwieldy given how many possibilities there are.
see https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf
"connection to the particular DBMS needs an ODBC driver : these may
come with the DBMS or the ODBC driver manager or be provided
separately by the DBMS developers, and there are third-party
developers"
Microsoft provides drivers for Ubuntu:
https://www.microsoft.com/en-us/download/details.aspx?id=50419
You can add dsn entries to the /etc/odbc.ini file in most linux distros. See this for ubuntu https://help.ubuntu.com/community/ODBC

Open MS Access file in Linux

I'm trying to open MS Access database file with QT in Linux.
So, I have installed Easysoft MS Access ODBC Driver with unixODBC. There is my odbc.ini file:
[Easysoft ODBC-ACCESS]
Description = MS Acess db driver
Driver = /usr/local/easysoft/access/lib/libesmdb.so
Setup = /usr/local/easysoft/access/lib/libesmdbS.so
and there is odbcinst.ini file:
[ACCESS_SAMPLE]
Driver = Easysoft ODBC-ACCESS
mdbfile = /home/user/personal_base.mdb
Also, I have installed odbc plugin for qt:
sudo apt-get install libqt4-sql-odbc
Now how can I open mdb-file with Qt in Linux?
In MS Windows I do it such way:
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:/personal_base.mdb");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"), db.lastError().text());
return false;
}
return true;
}
I try to change db.setDataBaseName to
...
db.setDatabaseName("Driver={Easysoft ODBC-ACCESS};DSN='ACCESS_SAMPLE'");
...
But it returns an error:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unale to connect
What's the matter?
Here is some code that I use for building the proper DSN for connecting to SQL Server from Mac, Linux, and Windows. I believe that your connection string isn't correct in your code. Perhaps it will help get you started.
QString SQLServerProvider::buildDSN(QString server, QString database, QString username, QString password)
{
#ifdef Q_WS_MACX
QString dsn = QString("DRIVER=/usr/local/lib/libtdsodbc.so;SERVER=%1;TDS_VERSION=8pClient;DATABASE=%2;PORT=1433;UID=%3;PWD=%4;").arg(server).arg(database).arg(username).arg(password);
#endif
#ifdef Q_WS_X11
QString dsn = QString("DRIVER={FreeTDS};SERVER=%1;TDS_VERSION=8.0;PORT=1433;DATABASE=%2;UID=%3;PWD=%4;").arg(server).arg(database).arg(username).arg(password);
#endif
#ifdef Q_WS_WIN
QString dsn = QString("DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;UID=%3;PWD=%4;").arg(server).arg(database).arg(username).arg(password);
#endif
return dsn;
}
I know that you are trying to connect to a Microsoft Access database, but perhaps if you replace FreeTDS and a few other paraneters in the Q_WS_X11 part, that will work for you. I have not used Easysoft ODBC-ACCESS before so I'm not 100% sure of how DSNs should be formatted for this driver. Have a read here if you haven't already as it explains how to test ODBC DSN connections using isql. If you need further assistance, let me know and I'll see what I can do to help.
Try changing your DSN-Less connection to look :-
Driver=/usr/local/easysoft/access/lib/libesmdb.so;mdbfile=/home/user/personal_base.mdb
Add your your machines library path :-
export LD_LIBRARY_PATH=/usr/local/easysoft/lib:/usr/local/easysoft/access/lib:/usr/local/easysoft/unixODBC/lib:$LD_LIBRARY_PATH
Finally email support#easysoft.com and ask them for the latest version of the driver.

Resources