Create New database,Table in SQL using Python

preview_player
Показать описание
Create New database,Table in SQL using Python

Code :

#python #sql
Рекомендации по теме
Комментарии
Автор

I am getting this error while creating database
pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]CREATE DATABASE statement not allowed within multi-statement transaction. (226) (SQLExecDirectW)')

import pyodbc

# Connect to the SQL Server
conn = pyodbc.connect(
"driver={sql server};"
"database=chinna;"
"server=DESKTOP-L3PIH4O;"
"trusted_connection=yes;"
)

# Create a cursor object
cursor = conn.cursor()

# Execute the CREATE DATABASE statement outside of any transaction
cursor.execute('CREATE DATABASE PyhtonSQL')

# Commit the transaction
conn.commit()

# Close the connection
conn.close()


please tell me the solution

PavankalyanSreesailam
Автор

It is showing error
CREATE DATABASE statement not allowed within multi-statement transaction
After i inserted the
conn.autocommit = True
It is showing different error

rajkumarrajan
welcome to shbcf.ru