[Python] SQLAlchemy example not working on Windows, but on Ubuntu with Docker

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    the code below works fine in a docker container on ubuntu, even without the import of pymssql. but does not on Windows (without docker). both target the same database server.

    the problems comes from engine.connect() which seems to run very long....

    pip lists pymssql as well mssql.

    any ideas, at least how to debug it?

    thanks in advance for any hints

    import streamlit as st
    import pandas as pd
    import pymssql
    from sqlalchemy import create_engine, text

    # specify the connection string
    server = "SRV-SQL\\xxx"
    database = "xxx"
    user = "xxx"
    password = "xxx"

    # Create an engine
    engine = create_engine(f'mssql+pymssql://{user}:{password}@{server}/{database}')

    # create a connection
    connection = engine.connect()

    # Define the query
    query = text("SELECT ProductNumber, Matchcode FROM ASEArtikel WHERE ProductNumber = 'A000001' OR ProductNumber = 'A000003'")
    # use the read_sql_query() function to read the data from the query to a dataframe
    df = pd.read_sql_query(query, connection)
    # close the connection
    connection.close()

    st.dataframe(df)

    Continue reading...

Compartilhe esta Página