SQL数据仓库,Python和SPROC

时间:2017-03-29 12:30:09

标签: python sql azure-sql-database

我有一个依赖链,我在Python脚本中每晚运行。此依赖关系链的一部分是通过MS SQL Server上的SPROC加载和转换数据。我们公司只是将我们的数据库迁移到Azure的SQL数据仓库,所以我开始转换依赖关系链,但现在我遇到了一个错误,我认为在尝试运行我们添加到服务器的SPROC时,它与ADW有关。我在SSMS中执行SPROC没有问题,但以下代码产生了后续错误:

import pyodbc

def conn_string_AZUREDW():

    Uid = '***'
    Pwd = '***'

    driver = '{SQL Server Native Client 11.0}'
    server = 'ourServer'
    database = 'ourDB'

    conn_string = 'driver=%s; server=%s; database=%s; Uid=%s; Pwd=%s;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30' % (driver, server, database, Uid, Pwd)
    return str(conn_string)  

connObjectADW = conn_string_AZUREDW()
connADW = pyodbc.connect(connObjectADW)
cursorADW = connADW.cursor()

cursorADW.execute('exec [schema].[sproc]')
connADW.commit()

错误:

ProgrammingError: ('42000', '[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]111212;Operation cannot be performed within a transaction. (111212) (SQLExecDirectW)')

SPROC的例子:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROC [schema].[sproc] AS
BEGIN

    [DROP TEMP TABLE IF OBJECT EXISTS]
    [SELECT INTO TEMP TABLE]

    [DROP REAL TABLE IF OBJECT EXISTS]
    [SELECT INTO REAL TABLE]

END
GO

有没有人有幸在Azure的SQL数据仓库中从Python执行SPROC?

0 个答案:

没有答案