CartoDB / odbc_fdw

PostgreSQL Foreign-data Wrapper for ODBC
Other
66 stars 22 forks source link

Unable to connect to MS SQL Server #140

Open reignmaker opened 7 months ago

reignmaker commented 7 months ago

Hello,

Thank you for maintaining this extension! Does this extension allow executing write queries on MS SQL Server?

Also I have some difficulties on setting up the extension and would like to get some help with it.

I went through the readme step by step installing all the dependencies (unixodbc-dev (2.3.11-1), odbc-postgresql (1:16), freetds-common (1.1.6-1.1), freetds-dev (1.1.6-1.1), freetds-bin (1.1.6-1.1)) and the extension itself make && sudo make install successfully.

The host system is Ubuntu 20.04.3 LTS and the Postgres 12.

/etc/odbcinst.ini:

[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
UsageCount=1

[PostgreSQL ANSI]
Description=PostgreSQL ODBC driver (ANSI version)
Driver=psqlodbca.so
Setup=libodbcpsqlS.so
Debug=0
CommLog=1
UsageCount=1

[PostgreSQL Unicode]
Description=PostgreSQL ODBC driver (Unicode version)
Driver=psqlodbcw.so
Setup=libodbcpsqlS.so
Debug=0
CommLog=1
UsageCount=1

CREATE EXTENSION odbc_fdw;

CREATE SERVER sqlserver_fdw FOREIGN DATA WRAPPER odbc_fdw
  OPTIONS (
   odbc_DRIVER '{ODBC Driver 18 for SQL Server}',
   "odbc_Server" '{***.***.windows.net}',
   "odbc_Database" '${dbname}',
   "odbc_UID" '{userName}',
   "odbc_PWD" '{paSSworD}'
  );

CREATE USER MAPPING FOR user
  SERVER sqlserver_fdw
  OPTIONS ("odbc_UID" '{userName}', "odbc_PWD" '{paSSworD}');

CREATE FOREIGN TABLE IF NOT EXISTS public.mssql_table (
    id integer NULL,
    ...
)
    SERVER sqlserver_fdw
    OPTIONS (schema 'schema_name', table 'table_name');

Attempting to select something (like select public.mssql_table or select * from odbctableslist('sqlserver_fdw', 1)) returns an error:

ERROR:  Connecting to driver 

SQL state: 58000

Am I missing something?

michelle0809 commented 6 months ago

I have same problem.