1

I am trying to connect to a sqlserver database and read my data into a data frame. This is my code below:

import pandas as pd
import sqlalchemy as sq

engine = sq.create_engine('mssql://ServerName/myDataBase?trusted_connection=yes')

df_sql = pd.read_sql_table("TableName",con=engine,schema="App")

I am getting this error message:

NotImplementedError: read_sql_table only supported for SQLAlchemy connectable.

I don't know if I am missing anything in the syntax to get this connection to read into a dataframe.

2
  • This answer is at the top of my internet search on the error message. Have you tried read_sql instead of read_sql_table? Commented Apr 15, 2021 at 12:46
  • @DanGuzman - The thing is that create_engine() returns an Engine object, specifically class Engine(Connectable, log.Identified), so it is a Connectable. And since df = pd.read_sql_table("team", con=engine, schema="dbo") works for me I must conclude that there's something else going on that OP isn't telling us. Commented Apr 15, 2021 at 14:14

1 Answer 1

0

you miss something, please try:

with engine.connect() as cnx:
    # Read the table into a DataFrame
    df = pd.read_sql_table("TableName", cnx, schema="App")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.