create_engine sqlalchemy with parsed url sql server 1

create_engine sqlalchemy with parsed url sql server

import urllib
params = urllib.parse.quote_plus("DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password")

engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)

Here is what the above code is Doing:
1. We’re using the urllib.parse.quote_plus() function to encode the connection string.
2. We’re using the create_engine() function from the sqlalchemy library to create an Engine for working with SQL Server.
3. We’re passing the connection string to the create_engine() function via the “mssql+pyodbc:///?odbc_connect=%s” % params.

Similar Posts