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.
Related
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.
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.
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");
I have a SQL Server database named pm-eng that I need to connect to from a linux box. I've setup unixODBC and configured my odbc.ini as follows:
[pm_production]
Driver = FreeTDS
Server = mssql.server
Database = pm-eng
When I test with iSQL, I get an error connecting saying that the the 'pm' database does not exist. I've tried wrapping the database name in [] and quotes with no luck. Ideally I would just change the name of the DB but that is not possible in this environment. I've verified my connection with a DB name that is not hyphenated and it works fine. Is it possible to connect to ODBC DSNs with hyphenated DB names?
Since you're connecting to a MSSQL database maybe you can try this:
[pm_production]
Driver = FreeTDS
Server = mssql.server
And then connect with a user who's default Database is pm-eng
According to documentation found on MSDN: "If Database is not specified, the default database defined for the login is used."
This turned out to be an issue with FreeTDS, not unixODBC. I needed to specify a TDS_Version in the odbc.ini file and it started working. Final config looks like this:
[pm_production]
Driver = FreeTDS
Server = mssql.server
Database = pm-eng
TDS_Version = 8.0
I have a Perl script on a Linux (Ubuntu 8.10) machine and I need to write data to a SQL Server Database. I've been trying to use the DBD::ODBC module but I can't get it to connect. Where can I get a free/open source driver to use to use for the ODBC connection or is there another way to do this from Perl on Linux?
I connect to SQL Server 2005 with the stack of unixODBC, freeTDS (this is the driver) and DBD::ODBC.
After you install these components, edit /etc/unixODBC/odbc.ini to read like this:
[DNS]
Description = my database
Driver = /usr/lib/libtdsodbc.so #path to freeTDS driver
Server = ServerName
Database = DatabaseName
Port = 1433 #sql server default port
TDS_Version = 9.0 #9.0 is sql server 2005
try domain login = yes
try server login = yes
nt domain = DOMAIN
If all goes well, you should be able to connect with:
$dbh = DBI->connect('dbi:ODBC:DNS', "userName", "passWord");
Good luck!
Use the DBD::Sybase module, at one point Sybase and MS SQL Server shared a common codebase.
You may also want to investigate the open source FreeTDS libraries. See the FreeTDS FAQ Question "Which Perl library should I use".