Search code examples
postgresqlms-access-2013

PostgreSQL odbc_fdw (64bit) Connection to MS Access (64bit)


I'm trying to link existing MS Access 2013 tables into a PostgreSQL 12 Database, both 64bit version and installed on a small network using odbc_fdw. The databases are on different machines on a windows network. I have a system DSN installed and checked (using pyodbc). In PostgreSQL I am able to create the extension; Foreign Data Wrappers; Foreign Server and Foreign Table, and to create the User Mappings, but when trying to run a query I get the "ERROR: Connecting to the driver". I tried numerous options following the little literature I found without any luck. I can use the ocdb_fwd to connect to a MySQL server straight forward but I could not figure out how to do it with MSAccess. I would deeply appreciate it if somebody can help me figure out how to connect MSAccess to the fdw if possible. These are my basic settings in PostgreSQL:

CREATE FOREIGN DATA WRAPPER odbc_data_wrapper
    HANDLER public.odbc_fdw_handler
    VALIDATOR public.odbc_fdw_validator;

CREATE SERVER odbc_msaccess
    FOREIGN DATA WRAPPER odbc_data_wrapper
    OPTIONS (dsn 'msaccess'); 

CREATE USER MAPPING FOR postgre SERVER odbc_msaccess
    OPTIONS("ocdb_UID" 'Admin', "ocdb_pwd" '');

CREATE FOREIGN TABLE test(
    id integer NOT NULL,
    name character varying NOT NULL
    )
    SERVER odbc_msaccess
    OPTIONS (layer 'test',
    sql_query 'SELECT id, name FROM test); 

DSN: msaccess working. Tested on pyodbc
odbc_data_wrapper: tested just fine connecting a MySql database

Solution

  • The databases are on different machines

    Yeah, that's likely not going to work.

    PostgreSQL needs direct access to the Microsoft Access Database, so it either has to be on the same machine, or on a network share. But if you're running it on a network share, you need to make sure that the user running PostgreSQL has access to the network share, the DSN is installed on the machine running PostgreSQL, and you're properly referring to the network path.