Hi, I'm new to python
I'm currently converting my .net application to python.
I'm trying to call database to extract some data.
I manage to call to mssql database using pyodbc, but when I tried to use pandas, it failed with error
this work fine
but when I want to try to use pandas
it get error mentioned above.
May I know why this happened?? and how to solve this issue?
btw, I'm using Windows 11 running on Macbook M1 Parallel Desktop.
I'm currently converting my .net application to python.
I'm trying to call database to extract some data.
I manage to call to mssql database using pyodbc, but when I tried to use pandas, it failed with error
Error:Exception has occurred: OperationalError
(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]Invalid connection string attribute (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)')
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Here is my pyodbc code1 2 3 4 5 |
connection_string = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=" + server + ";DATABASE=" + database + ";UID=" + username + ";PWD=" + password conn = pyodbc.connect(connection_string) cursor = conn.cursor() cursor.execute( f "SELECT COUNT(*) FROM [98_PRODUCTS] WHERE SKU = ?" , (sku,)) count = cursor.fetchone()[ 0 ] |
but when I want to try to use pandas
1 2 |
engine = create_engine( 'mssql+pyodbc://{username}:{password}@{server}/{database}?driver=ODBC+Driver+17+for+SQL+Server&connect_timeout=30' ) data = pd.read_sql(query, engine) |
May I know why this happened?? and how to solve this issue?
btw, I'm using Windows 11 running on Macbook M1 Parallel Desktop.
buran write Dec-06-2023, 08:00 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.