Reputation: 14938
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.
Upvotes: 2
Views: 779
Reputation: 122376
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).
Upvotes: 1