MSSQL2008 - Pyodbc - Previous SQL was not a query

前端 未结 8 1417
我寻月下人不归
我寻月下人不归 2020-12-05 04:13

I can\'t figure out what\'s wrong with the following code, The syntax IS ok (checked with SQL Management Studio), i have access as i should so that works too.. but for some

8条回答
  •  失恋的感觉
    2020-12-05 04:57

    Just in case some lonely net nomad comes across this issue, the solution by Torxed didn't work for me. But the following worked for me.

    I was calling an SP which inserts some values into a table and then returns some data back. Just add the following to the SP :

    SET NOCOUNT ON
    

    It'll work just fine :)

    The Python code :

        query = "exec dbo.get_process_id " + str(provider_id) + ", 0"
        cursor.execute(query)
    
        row = cursor.fetchone()
        process_id = row[0]
    

    The SP :

    USE [DBNAME]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[GET_PROCESS_ID](
        @PROVIDER_ID INT,
        @PROCESS_ID INT OUTPUT
    )
    AS
    BEGIN
        SET NOCOUNT ON
        INSERT INTO processes(provider_id) values(@PROVIDER_ID)
        SET @PROCESS_ID= SCOPE_IDENTITY()
        SELECT @PROCESS_ID AS PROCESS_ID
    END
    

提交回复
热议问题