我尝试在两种情况下执行 T-SQL 查询(我使用 Win7、python 3.2、MS SQL Server express 2008、pyodbc for python 3.2):
-情况1:
使用 MS SQL Server Management Studio 我尝试执行查询:
USE master;CREATE DATABASE Sales ON (NAME = Sales_dat,FILENAME = 'C:\saledat.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON ( NAME = Sales_log, FILENAME = 'C:\salelog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB );
它返回成功的结果
-案例2:
import pyodbc
cxnn=pyodbc.connect('DSN=SERVER;UID=sa;PWD=password')
cur=cxnn.cursor()
cur.execute("USE master;CREATE DATABASE Sales ON (NAME = Sales_dat,FILENAME = 'C:\saledat.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON ( NAME = Sales_log, FILENAME = 'C:\salelog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB );")
cxnn.commit()
但是在运行代码后我收到错误
pyodbc.Error: ('HY000', 'The driver did not supply an error!')
如果我没有运行代码
cxnn.commit()
我没有收到任何错误。但为什么?