-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request
Description
Describe the bug
Got error AttributeError: module 'mssql_python' has no attribute 'connect'
If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message:
Stack trace:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 8
6 MSSQLPASSWORD = os.getenv("MSSQLPASSWORD")
7 connection_string = f"SERVER=localhost;DATABASE=StackOverflow2013;UID=sa;PWD={MSSQLPASSWORD};Encrypt=yes;"
----> 8 connection = mssql_python.connect(connection_string)
10 # Execute a query
11 cursor = connection.cursor()
AttributeError: module 'mssql_python' has no attribute 'connect'
To reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
import mssql_python
import os
# Establish a connection
# Specify connection string
MSSQLPASSWORD = os.getenv("MSSQLPASSWORD")
connection_string = f"SERVER=localhost;DATABASE=StackOverflow2013;UID=sa;PWD={MSSQLPASSWORD};Encrypt=yes;"
connection = mssql_python.connect(connection_string)
# Execute a query
cursor = connection.cursor()
cursor.execute("select top 10 Id, DisplayName, Location from dbo.Users;")
rows = cursor.fetchall()
for row in rows:
print(row)
# Close the connection
connection.close()
Expected behavior
Expected to receive 10 rows as resultset to be printed to console screen.
Further technical details
Python version: 3.12.3
SQL Server version: SQL Server 2022 (RTM-CU18) on Podman
Additional context
Hypervisor Host (Client host) - Ubuntu 24.04
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request