CREATE DATABASE command can't be parameterized on SQL Server?

39 views
Skip to first unread message

Richard Tolar

unread,
Nov 11, 2010, 12:07:19 PM11/11/10
to pyodbc
Are some commands not parameterizable, such as Create Database?

SQL Server 2008
current version of pyodbc for python 2.6

script:
------------------
import pyodbc
connection = pyodbc.connect('DRIVER={SQL
Server};SERVER=AAA;UID=BBB;PWD=CCC',autocommit=True)
cursor = connection.cursor()
cursor.execute('create database ?', 'richard_test_6')
-----------------
Fails with

Traceback (most recent call last):
File "C:\dev\atsm_31\trunk\db\foo.py", line 5, in <module>
cursor.execute('create database ?', 'richard_test_6')
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL
Server Driver][
SQL Server]Incorrect syntax near '@P1'. (102) (SQLExecDirectW);
[42000] [Microso
ft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be
prepared. (8180)")



If you replace the last line with:
#cursor.execute('create database richard_test_6')

it works.

Reply all
Reply to author
Forward
0 new messages