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

Sqlalchemy with pytds #220

Open
ifuchs opened this issue Dec 10, 2022 · 1 comment
Open

Sqlalchemy with pytds #220

ifuchs opened this issue Dec 10, 2022 · 1 comment

Comments

@ifuchs
Copy link

ifuchs commented Dec 10, 2022

I have Jupyter notebook in which I am able to access using pytds. I would like to use it with sqlalchemy and the %%sql command.

however when try the following:
sqlalchemy.create_engine('mssql+pytds://user:pw@ip/db')
I get:
Engine(mssql+pytds://user:***@ip/db)
and then I do %load_ext sql
and
%%sql

Select ...

The result is : Done.
(pytds.tds_base.ProgrammingError) Previous statement didn't produce any results
(Background on this error at: https://sqlalche.me/e/14/f405)

I know the select produces a result if I just do:
import pytds
with pytds.connect('ip, 'db', 'sa', pw as conn:
with conn.cursor() as cur:
cur.execute("SELECT ...")
a = cur.fetchall()
print(a)

In order to eliminate any possibility of an SQL syntax error, I tried this:
%%sql mssql+pytds://userid:password@serverip:1433/dbname
SELECT * from sysobjects where xtype = 'U'

and once again I got:
Done.
(pytds.tds_base.ProgrammingError) Previous statement didn't produce any results
(Background on this error at: https://sqlalche.me/e/14/f405)

How to get sqlalchemy and the sql extension to work?

@yafimvo
Copy link

yafimvo commented Dec 27, 2022

@ifuchs
Try to disable the autocommit option

%config SqlMagic.autocommit=False

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

No branches or pull requests

2 participants