[Chicago] pyodbc to ms access

Pat P. paaschpa at gmail.com
Mon May 9 11:49:22 EDT 2016


Sample code (below) that 'works on my machine (tm)'. I'm running 32 bit
Python 2.7.3, MS Access 2007 (can't tell if 32 or 64...shows nothing where
'bit' should be...guessing 32 bit?) and Windows 7 64 bit.

import pyodbc
cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb,
*.accdb)};DBQ=C:\Users\ppaasch\Documents\MSAccessPython\Database1.accdb;')

crsr = cnxn.cursor()
for table_name in crsr.tables(tableType='Table'):
  print(table_name)

HTH,
Pat

On Mon, May 9, 2016 at 7:17 AM, Noah Schultz <noah_schultz at oxfordcorp.com>
wrote:

> First, he is on the right path about the  32 bit vs 64 bit issue. Second,
> ms access is weak sauce and he should use a much more robust db with better
> python integration.
>
> Sent from my iPhone
>
> On May 9, 2016, at 7:04 AM, Jeremy McMillan <jeremy.mcmillan at gmail.com
> <mailto:jeremy.mcmillan at gmail.com>> wrote:
>
>
> You probably need to exhume a "Jet" db file format parser. Take a deep
> breath. Maybe there's ODBC, but probably not.
>
> On Mon, May 9, 2016, 06:29 Aaron Elmquist <elmq0022 at umn.edu<mailto:
> elmq0022 at umn.edu>> wrote:
>
> Does anyone have some advice or insight on connecting to an MS Access
> Database using python?
>
> Here's my info:
>
> Connection String:
>
>     r'DRIVER={Microsoft Access Driver (*.mdb,
> *.accdb)};DBQ=C:\Path\to\DB\db.mdb;'
>
> Python Version:
>
>     Python 3.5.1 :: Continuum Analytics, Inc. - 64 bit
>
> OS
>
>     Windows 7
>
> Office
>
>     32 Bit
>
> Here's my error:
>     Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source
> name not found and no default driver specified (0) (SQLDriverConnect)')
>
> but...
>
> pyodbc.dataSources() returns:
>     {'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)'}
>
> Do I need to use a 32 bit python to get this done?
> Can I specify the python bits version to use in a specific conda env?
>
> Thanks,
>
> Aaron
> _______________________________________________
> Chicago mailing list
> Chicago at python.org<mailto:Chicago at python.org>
> https://mail.python.org/mailman/listinfo/chicago
> _______________________________________________
> Chicago mailing list
> Chicago at python.org<mailto:Chicago at python.org>
> https://mail.python.org/mailman/listinfo/chicago
>
> The information transmitted, including attachments, is intended only for
> the person or entity to which it is addressed and may contain confidential
> and/or privileged material. Any review, retransmission, dissemination or
> other use of, or taking of any action in reliance upon this information by
> persons or entities other than the intended recipient is prohibited. If you
> received this e-mail in error, please notify the sender immediately by
> replying to the message and deleting the material from your computer.
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20160509/0be1a1bf/attachment-0001.html>


More information about the Chicago mailing list