Connection error to Access database

前端 未结 3 712
醉梦人生
醉梦人生 2021-01-21 15:39

I wrote the program which by means of pyodbc is connected to Access to that it was very glad. Help me please.

import pyodbc
#import kinterbasdb
import firebirdsq         


        
相关标签:
3条回答
  • 2021-01-21 15:57

    The driver name you specified...

    DRIVER={Microsoft Access Driver (*.accdb)}

    ...is incorrect. There is no ODBC driver with that name. 32-bit applications that want to open an older .mdb database file can use

    Driver={Microsoft Access Driver (*.mdb)}

    To open an .mdb file from a 64-bit application, or to open an .accdb file from any application, you need to use

    Driver={Microsoft Access Driver (*.mdb, *.accdb)}

    0 讨论(0)
  • 2021-01-21 15:57

    This might help.

    import pyodbc
    
    # Connect to your access database file
    
    DBfile = 'Filename.mdb'  # Let your file name <Filename> and access extension .mdb
    conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+DBfile)  #    user/password can be used
    cur = conn.cursor()
    
    # Create new table in database
    
    cur.execute ('CREATE TABLE CLIENTS (ID INTEGER, COMPANY STRING)')
    conn.commit()
    
    cur.close()
    conn.close()
    
    0 讨论(0)
  • 2021-01-21 16:04

    It looks like you do not have connected to the DB. Maybe you should begin with a smaller program just to connect. Samples in other questions : Using Microsoft Access SQL operators in Python ODBC

    0 讨论(0)
提交回复
热议问题