How To Create And Delete Database Using Mssql+pyodbc Connection String Using Python
I have a database engine as the below: from sqlalchemy import create_engine import pydoc # connect db engine = create_engine('mssql+pyodbc://xxxx\MARTRNO_EXPRESS/toolDB?driver=SQL
Solution 1:
Well! I solved this by creating a new connection in database
.py file as the below code and by adding the autocommit = True
:
conn = pyodbc.connect("driver={SQL Server};server=WINKPN-3B5JTT2\SMARTRNO_EXPRESS; database=master; trusted_connection=true",
autocommit=True)
And Tried to access this connection by the below code:
from database import connec
def create_all_tables_from_db():
create_all_tables_query = "CREATE DATABASE MyNewDatabase"
connec.conn.execute(create_all_tables_query)
create_all_tables_from_db()
Post a Comment for "How To Create And Delete Database Using Mssql+pyodbc Connection String Using Python"