Skip to content
Advertisement

SQL query fails when using pyodbc, but works in SQL

I am having some trouble with what should be a very simple script. I am just trying to create a new SQL Server database using the Python pyodbc module. The “sqlcommand” parameter I am attempting to pass in works perfectly when I execute it in SQL Server 2012, but it is failing from this python script. Not sure what is going wrong, anyone have any ideas?

and the errors:

Advertisement

Answer

GO is a batch terminator in SQL Server Management Studio. It doesn’t make any sense in pyodbc. Instead, issue separate commands from your script.

Updated Code:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement