0
votes

I am using a Windows 10 machine trying to connect to an SQL Serve (SQL Developer 2017) using Python. My code is as follows:

from sqlalchemy import create_engine engine = create_engine('mssql+pymssql://Sonwabo:helpdeskNo1@localhost:1433/dbname') connect = engine.connect()

I get the following error: pymssql.OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost:1433)\nNet-Lib error during Unknown error (10060)\n')

2

2 Answers

0
votes

I remember my sqlalchemy connection being very finicky when connecting to SQL Server too. I had to do some experimenting with drivers and switching between pymssql and pyodbc. This is what ended up working for me.

server = 'server'
username = 'user'
password = 'pass'
driver = 'ODBC+DRIVER+17+for+SQL+Server'
engine_stmt = 'mssql+pyodbc://{}:{}@{}/{}?driver={}'.format(username,
                                                            password,
                                                            server,
                                                            database,
                                                            driver)
engine = sqlalchemy.create_engine(engine_stmt)
0
votes

I think you should follow as the format below.

server = ‘ServerAddress' 
database = 'DataBaseName' 
username = 'UserName' 
password = 'Password'
driver = 'SQL Server Native Client 11.0'
DataBase_connection = f'mssql://{username}:{password}@{server}/{database}?driver={driver}'


engine = create_engine(DataBase_connection)
connection = engine.connect()