Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSN is not resolved when called from Excel #58

Open
staticlibs opened this issue Feb 14, 2025 · 3 comments · May be fixed by #61
Open

DSN is not resolved when called from Excel #58

staticlibs opened this issue Feb 14, 2025 · 3 comments · May be fixed by #61

Comments

@staticlibs
Copy link
Contributor

Until now, I have not been using python ODBC. Let me install it on my windows box...

done...

Trying now with my zzz DSN which for me is defined as

Image

print(pyodbc.connect("DSN=zzz;").cursor().execute("select current_catalog()").fetchone())

... succeeds and reports the database

Image

So, pyodbc is "playing nice" with the windows ODBC driver.

But, on the same windows box, "Excel > Data > Get Data > Other Source > ODBC", as follows:

Image

fails, returning:

Image

@staticlibs I thank you for your effort in recreating my situation with db on network path. Would you be willing to try querying your duck_user_2 connection from Excel?

FWIW, even trying @shwivel 's workaround, like this:

Image

continues to use :memory:

Image

Note: everything under Excel works when I use a DSN defined to use sqlite ODBC driver to connect with sqlite database exported from duckdb. So, it does not seem to be an Excel problem, rather DuckDB seems to provide incomplete support for connection options.

Originally posted by @malcook in #29

@staticlibs
Copy link
Contributor Author

@malcook

Thanks for the screenshots, I am able to reproduce this in Excel 2016. Moving to the new issue, because it looks to be specific to Excel/Query Editor.

Image

Image

> python
Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
>>> print(pyodbc.connect("DSN=user_test_3;").cursor().execute("select current_catalog()").fetchone())

('test3',)

@staticlibs
Copy link
Contributor Author

@malcook

In my environment it appeared to be caused by the credentials that are being appended to the ODBC connection string by Excel. When credentials are included - this confuses the DuckDB ODBC driver and it cannot find the DSN:

>>> import pyodbc
>>> print(pyodbc.connect("DSN=user_test_3;").cursor().execute("select current_catalog()").fetchone())
('test3',)
>>> print(pyodbc.connect("DSN=user_test_3;UID=foo;PWD=bar;").cursor().execute("select current_catalog()").fetchone())
('memory',)

This needs to be fixed in the DuckDB ODBC Driver, meanwhile the workaround for Excel is to delete the default credentials for DuckDB DSNs:

Image

Image

Image

After that, when new Query Editor is being opened, it is necessary to choose "Default or Custom" instead of "Database" in the corresponding dialog:

Image

Image

Image

@malcook
Copy link

malcook commented Feb 14, 2025

Thanks. This "workaround" works around for me.

staticlibs added a commit to staticlibs/duckdb-odbc that referenced this issue Feb 16, 2025
When the ODBC data source is used from Excel/Power Query, additional
options may be added to connection string automatically without showing
them to user. It was discovered in duckdb#58 that `UID` and `PWD` options are
added when user has credentials registered for this DSN in Excel.

DuckDB driver does not recognize these options and currently cannot
process them properly (see duckdb#59 for details). However the driver
knows about possible `trusted_connection` Excel/Power Query option and
ignores it successfully. It is proposed to also add `UID` and `PWD`
to the existing ignore list.

In the light of duckdb#60, that fixes the handling for unsupported options,
this change is not strictly necessary, but it still may be better to
consistently ignore all unneeded Excel/Power Query options and to not
register diagnostic messages for them.

Testing: existing Excel/Power Query ignore list test is extended to
include new options.

Fixes: duckdb#58
@staticlibs staticlibs linked a pull request Feb 16, 2025 that will close this issue
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this issue Feb 19, 2025
When the ODBC data source is used from Excel/Power Query, additional
options may be added to connection string automatically without showing
them to user. It was discovered in duckdb#58 that `UID` and `PWD` options are
added when user has credentials registered for this DSN in Excel.

DuckDB driver does not recognize these options and currently cannot
process them properly (see duckdb#59 for details). However the driver
knows about possible `trusted_connection` Excel/Power Query option and
ignores it successfully. It is proposed to also add `UID` and `PWD`
to the existing ignore list.

In the light of duckdb#60, that fixes the handling for unsupported options,
this change is not strictly necessary, but it still may be better to
consistently ignore all unneeded Excel/Power Query options and to not
register diagnostic messages for them.

Testing: existing Excel/Power Query ignore list test is extended to
include new options.

Fixes: duckdb#58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants