1

Where is the server name found in the SQL Alchemy session or engine?

I prefer not parsing the query property.

e = connManager.get_engine()

e.engine.url

mssql+pyodbc:///?odbc_connect=DRIVER={SQL Server Native Client 11.0};SERVER=myhost;DATABASE=mydatabase;TRUSTED_CONNECTION=Yes
database:''
drivername:'mssql+pyodbc'
host:None
password:None
port:None
query:{'odbc_connect': 'DRIVER={SQL Server ...CTION=Yes'}
'odbc_connect':'DRIVER={SQL Server Native Client 11.0};SERVER=myHost;DATABASE=mydatabase;TRUSTED_CONNECTION=Yes'
__len__:1
username:None

1 Answer 1

1

I don't think the server name alone is stored in the Engine object anywhere, but you could always ask pyodbc to interrogate the driver:

import pyodbc

# ...

cnxn = engine.raw_connection()
server_name = cnxn.getinfo(pyodbc.SQL_SERVER_NAME)
print(server_name)  # GORD-HP\SQLEXPRESS
Sign up to request clarification or add additional context in comments.

1 Comment

Which pyodbc property gets the schema name?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.