fail to make pyodbc-4.0 64bit find excel driver (windows10-64bit) - pyodbc

I don't catch how to connect to my excel file with pyodbc4, on windows 10 64 bit (python-3.6). As anybody a clue on my error in this code ?
import pyodbc
import os
sources = pyodbc.dataSources()
dsns = list(sources.keys())
dsns.sort()
sl = []
for dsn in dsns:
sl.append('%s [%s]' % (dsn, sources[dsn]))
print('\n'.join(sl))
# DATABASE CONNECTION
filename = 'C:\\WinPython\\basedir36\\buildZero\\winpython-64bit-3.6.x.1\\notebooks\\test.xls'
assert os.path.exists(filename)
# was wrong: CNXNSTRING = 'Driver={Microsoft Excel Driver (*.xls)};DBQ=%s;READONLY=FALSE' % filename
CNXNSTRING = 'Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=%s;READONLY=FALSE' % filename
print ('CNXNSTRING is ', CNXNSTRING)
cnxn = pyodbc.connect(CNXNSTRING, autocommit=True)
result-in-64bit:
>>>
RESTART: C:/WinPython/basedir36/buildZero/winpython-64bit3.6.x.1/notebooks/TEST6.py
Excel Files [Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)]
MS Access Database [Microsoft Access Driver (*.mdb, *.accdb)]
dBASE Files [Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)]
CNXNSTRING is Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=C:\WinPython\basedir36\buildZero\winpython-64bit-3.6.x.1\notebooks\test.xls;READONLY=FALSE
Traceback (most recent call last): File "C:/WinPython/basedir36/buildZero/winpython-64bit-3.6.x.1/notebooks/TEST6.py", line 17, in <module>
cnxn = pyodbc.connect(CNXNSTRING, autocommit=True)
pyodbc.Error: ('IM002', '[IM002] [Microsoft][Gestionnaire de pilotes ODBC] Source de donn�es introuvable et nom de pilote non sp�cifi� (0) (SQLDriverConnect)')
>>>
NEW findings: it works if I use pyodbc4- 32 bit and python-3.6 32 bit... so how to make it work in 64 bit ?
result-in-32bit:
>>>
RESTART: C:\WinPython\basedir36\buildZero\winpython-32bit-3.6.x.1\notebooks\TEST6.py
Excel Files [Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)]
MS Access Database [Microsoft Access Driver (*.mdb, *.accdb)]
dBASE Files [Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)]
CNXNSTRING is Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=C:\WinPython\basedir36\buildZero\winpython-64bit-3.6.x.1\notebooks\test.xls;READONLY=FALSE
>>>

it works if I use pyodbc4- 32 bit and python-3.6 32 bit... so how to make it work in 64 bit ?
If the script is running under 64-bit Python then it needs to have the 64-bit version of the Excel ODBC driver installed.
There is an old office 2007 32 bit on this pc
It is possible to do a "forced install" of the 64-bit Access Database Engine (which includes the Access and Excel ODBC drivers) alongside a 32-bit version of Office, but that is not recommended because in some circumstances it can break the Office install. (It is called a "forced install" because the default behaviour of the Access Database Engine installer is to prevent it from happening.)
If the "old office 2007" is no longer being used then you can uninstall it and then install the 64-bit version of the Access Database Engine. If it is still being used then you probably should just stick with running the Python script as 32-bit.

Related

Connect to HSQLDB 2.5 via Windows ODBC PostgreSQL driver

I am having a problem configuring the Windows PostgreSQL ODBC driver to connect to HSQLDB 2.5.0. As per the HSQLDB documentation I have installed version 11.01 of the PostgreSQL ODBC driver. When I test the connection from the ODBC Data Source Administrator I see the following in the ODBC log file: [0.000]Driver Version='11.01.0000,May 24 2019' linking 1915 dynamic Multithread library
[0.000]PQconnectdbParams: host='localhost' port='9001' dbname='test' user='test' sslmode='disable' password='test'
[0.109]PQsendQuery: 000000000033BCA0 'SET DateStyle = 'ISO';SET extra_float_digits = 2;show transaction_isolation'
[0.109] (ERROR) 42501 'user lacks privilege or object not found: DATESTYLE'
[1.157]PQfinish: 000000000033BCA0
It looks like the driver is sending a "SET DateStyle" command that HSQLDB doesn't understand. I've tried changing all the datasource options with no success. I have tried both the Unicode and ANSI versions of the driver.
The documentation on the web site is for version 2.5.1 which is in Release Candidate stage. You can download a snapshot jar from http://hsqldb.org/download/

Missing component (ACE0DBC.DLL) when I try to use pyodbc in python 3.6

I am using the 32-bit version on python and, although my computer is a 64-bit computer, I have successfully installed pyodbc 32-bit windows version. My Microsoft Access is also the 32 bit version.
When I query pyodbc for drivers, it shows both drivers.
[x for x in pyodbc.drivers() if x.startswith('Microsoft Access Driver')]
yields
['Microsoft Access Driver (*.mdb)', 'Microsoft Access Driver (*.mdb, *.accdb)']
Using examples in other places, I build a connection string "c" as follows
c= (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=C:\users\815001\Documents\Database6.accdb;'
)
I then try to connect with
cnxn=pyodbc.connect(c)
This results in the following error message:
Traceback (most recent call last):
File "", line 1, in
cnxn=pyodbc.connect(c)
pyodbc.InterfaceError: ('IM003', '[IM003] Specified driver could not be loaded due to system error 126: The specified module could not be found. (Microsoft Access Driver (*.mdb, *.accdb), C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE16\ACEODBC.DLL). (160) (SQLDriverConnect)')
I have checked the location and indeed there is no ACE0DBC.DLL file in C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE 16.
Where do I go to get it? I tried looking up ACE0DBC.DLL in the search engine on this web page and it yielded no results.
You can get Microsoft Access Database Engine 2016 here:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=54920

ODBC Issue in Red Hat linux release 6.9:

ODBC Issue
The database reported an error: [unixODBC][Driver Manager]Data Source name not found, and no default driver specified
As shown as below, QT application trying to connect a database file of type DBF (.dbf), when we try to execute the application we got the above error.
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QODBC");
QString str("DRIVER={Microsoft dBase Driver (*.dbf)}; DBQ=/path/to/dbf/files");
db.setDatabaseName(str);
if(db.open())
{
...
}
else
{
...// Failure
}
Referred the link (https://www.easysoft.com/support/kb/kb01039.html) and followed the below steps:
The configuration files odbc.ini and odbcinst.ini are present with the appropriate content.
Exported the variables ODBCSYSINI, ODBCINSTINI and ODBCINI with /etc/odbc.ini, /etc/odbcinst.ini and /home/user/.odbc.ini
From the same shell where we have exported the variables, tried to execute the application however encountered with the error "The database reported an error: [unixODBC][Driver Manager]Data Source name not found, and no default driver specified
Please find the content of the odbc.ini and odbcinst.ini
odbc.ini file:
[ODBC Data Sources]
TestODBC=MyODBCDriver
[TestODBC]
Driver=path/to/driver file
DataDirectory=path/to/where my dbf files resides
[Default]
Driver=path/to/driverfile
DataDirectory=path/to/where my dbf files resides
odbcinst.ini file:
[ODBC Drivers]
MyODBCDRIVER=Installed
[MyODBCDriver]
Description=ODBC Driver
Driver=/path/to Driver file
[ODBC]
Trace = Yes
Please provide any suggestion or solution to resolve the issue

Connect R to MS Access 64bit Windows

I'm trying to connect R with an MS Access database on a Windows 7 64bit machine.
library(RODBC)
con <- odbcConnectAccess2007("M:/path/to/mydatabase/my.database.accdb")
# [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifiedODBC connection failed
I've also tried package odbc using connection strings specified at https://www.connectionstrings.com/access/ but similarly cannot connect
library(DBI)
con <- dbConnect(drv = odbc::odbc(), dsn = "Microsoft Access Driver", driver = "Microsoft Access Driver (*.mdb, *.accdb)", database = "M:/path/to/mydatabase/my.database.accdb")
# Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
What am I doing wrong?
You can use my AceOdbcCheck script to test your machine for a valid install of Access "ACE" ODBC. If you don't have it installed you can download the drivers here.
Note that the "bitness" (64-bit or 32-bit) of the Access ODBC driver must match the version of R you are running. That is, if you are running 32-bit R then you need the 32-bit drivers even though you are running 64-bit Windows.

SQLite3 on ODBC Driver: string connection error

I'm trying to connect to SQLite through ODBC/Windows 7 with VbScript.
Using Werner's SQLite ODBC driver (http://www.ch-werner.de/sqliteodbc) to connect to a local SQLite file (c:\test.db).
Using the connection string suggest at https://www.connectionstrings.com/sqlite3-odbc-driver
Dim dbConn : Set dbConn = CreateObject("ADODB.Connection")
ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=c:\test.db;LongNames=0;Timeout=1000;NoTXN=0; SyncPragma=NORMAL;StepAPI=0;"
dbConn.open ConnectionString
I already tried reinstalling the driver and restarting the system. The error message is always there:
Error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Code: 80004005
Source: Microsoft OLE DB Provider for ODBC Drivers
Any ideas?
Quoted from the SQLite ODBC Driver developer (Christian):
Check your installation. Version 0.992 is pretty old, current version
is 0.999. If you have a 64 bit Windows, install both 64 and 32 bit
drivers. It could be that the VB stuff is still 32 bit.
The program launching the script was 32Bit (despite the OS is 64Bit). Hence the need to install both 32 and 64Bit versions of the driver.

Resources