Cannot load data to sql database #1159
-
Please first make sure you have looked at:
EnvironmentTo diagnose, we usually need to know the following, including version numbers. On Windows, be
ERROR: (pyodbc.OperationalError) ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)') Code: df.to_sql(table, f"mssql+pyodbc://ERRSTSDBP2/{user}:{password}@{server}/{dbname}?driver=ODBC+Driver+17+for+SQL+Server", if_exists='append', index=False) I already stablished a connection with the server in other codes, using pyodbc, not sure why is not working just in this one. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
It doesn't look like you're using pyODBC directly, could you try connecting directly? |
Beta Was this translation helpful? Give feedback.
-
@gordthompson , I got the same error: Expected URI to be a string, got <class 'sqlalchemy.engine.base.Engine'>. |
Beta Was this translation helpful? Give feedback.
-
Leave pandas' import pyodbc
user = 'Periquito'
password = 'PinPinPinPan'
server = 'internal-tools-db.devfacebook.com'
dbname = 'AdManagementTool'
driver='{ODBC Driver 17 for SQL Server}'
connection_string = (
f"Driver={driver};"
f"Server={server};"
f"Database={dbname};"
f"UID={user};"
f"PWD={password};"
)
cnxn = pyodbc.connect(connection_string)
crsr = cnxn.cursor()
result = crsr.execute("SELECT 'Connected!' AS foo").fetchval()
print(result) If not, then please post the complete stack trace. |
Beta Was this translation helpful? Give feedback.
-
This is not a pyodbc issue. It is an issue with SQLAlchemy, or pandas, or something else. |
Beta Was this translation helpful? Give feedback.
This is not a pyodbc issue. It is an issue with SQLAlchemy, or pandas, or something else.