Python Forum
sqlalchemy error connecting to SQL Server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sqlalchemy error connecting to SQL Server
#1
Hello everyone,

I just moved to a new company and the IT installed anaconda python for me as well local SQL server (SQL Express).

I usually use the sqlalchemy to connect to sql server and run queries and read/write tables from SQL Server.

My local server name is: LL-Anthon\SQLExpress
my database name: DB_Client_Portfolio

Here is my connection code to SQL using sqlalchemy:
import pandas as pd
import sqlalchemy as sqla

engine = sqla.create_engine(r'mssql+pyodbc://LL-Anthon\SQLExpress/DB_Client_Portfolio?trusted_connection=yes&driver=ODBC+Driver+17+for+SQL+Server')

df = pd.read_sql('Client', engine)
Here is the Error I get:
Error:
OperationalError: (pyodbc.OperationalError) ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. (-1) (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. (-1)') (Background on this error at: https://sqlalche.me/e/20/e3q8)
I made sure i have admin access on the computer but still the same problem.

any ideas please ?

Thank you in advance
Reply
#2
Try.
import pandas as pd
import sqlalchemy as sqla

# Connection string with double backslashes
engine = sqla.create_engine('mssql+pyodbc://LL-Anthon\\SQLExpress/DB_Client_Portfolio?trusted_connection=yes&driver=ODBC+Driver+17+for+SQL+Server')

df = pd.read_sql('Client', engine)
Check services running.
net start | find "SQL Server (SQLEXPRESS)"
Ping the SQL Server Host:
ping LL-Anthon
Reply
#3
I tried double backslashes... same result !

as for the net start and ping all worked fine !!!


(Jul-11-2024, 07:19 PM)snippsat Wrote: Try.
import pandas as pd
import sqlalchemy as sqla

# Connection string with double backslashes
engine = sqla.create_engine('mssql+pyodbc://LL-Anthon\\SQLExpress/DB_Client_Portfolio?trusted_connection=yes&driver=ODBC+Driver+17+for+SQL+Server')

df = pd.read_sql('Client', engine)
Check services running.
net start | find "SQL Server (SQLEXPRESS)"
Ping the SQL Server Host:
ping LL-Anthon
Reply
#4
Issue Solved...

knowing that i have all privileges and accesses on both sql server express and python, but both (sql server express and python) were installed from my user on my computer. and then admin gave me all accesses and privileges on my domain user.

I contacted my the IT director, took an admin user, removed sql server express and python from my physical computer.

Restarted my pc, logged in as admin and installed both sql server express and python, gave all necessary privileges to my user on the domain.

Restarted my pc, logged in with my domain user and all worked fine.

At the end this is how it worked to me.

Thank you all

Anthony
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020