2

I have an app that uses both pyodbc and SqlAlchemy for reasons (yes I know about engine.execute())

As a result I have to have a connection string in two formats:

mssql+pyodbc://./MyDb?APP=Python App
DRIVER={SQL Server};Server=localhost;Database=master;Trusted_Connection=Yes

Is there some function to let me convert from one to another so I can only have one configuration string in my configuration file.

1 Answer 1

1

Store each of the components of the database details in the configuration file (server, database name, settings, etc) and write two functions that construct the strings for SQLAlchemy and pyodbc.

For SQLALchemy you can also use the sqlalchemy.engine.url.URL object for this purpose (this object can be used in various places but also to construct the string).

Sign up to request clarification or add additional context in comments.

Comments

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.