Call the stored procedure on the remote sqlserver server with Python. Code fragment:
conn = pyodbc.connect(SERVER=host, UID=user, PWD=password, DATABASE=dbname,
DRIVER=driver)
cur = conn.cursor()
if not cur:
raise (NameError, 'Database connection error)
else:
cur.execute("EXEC GetLastData")
resList = list()
resList = cur.fetchall()
Execution error:
pyodbc.ProgrammingError: No results. Previous SQL was not a query.
After checking, the stored procedure can be executed normally in the sqlserver environment. It seems that there is a problem when calling pyodbc. A similar problem is found on stackoverflow. The answer is as follows:
the problem was solved by adding set NOCOUNT on; to the beginning of the anonymous code block. That statement suppresses the record count values generated by DML statements like UPDATE … and allows the result set to be retrieved directly.
The problem is solved by adding it to the beginning of the anonymous code block. This statement suppresses the record count value generated by the DML statement and allows the set result to be retrieved directly. SET NOCOUNT ON; UPDATE …
So add a sentence set NOCOUNT on
to the stored procedure
CREATE proc [dbo].[GetLastData]
AS
BEGIN
SET NOCOUNT ON
declare @begindate datetime,@enddate datetime
select @begindate=CONVERT(varchar(7),GETDATE(),120)+'-01'
select @enddate=DATEADD(MONTH,1,@begindate)
Read More:
- [Solved] sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, “You have an error in your SQ
- [Solved] pymysql.err.ProgrammingError: (1064, ‘You have an error in your SQL syntax;
- [SQL ERROR] SQL Error: could not execute statement & query did not return a unique result: 2; nested excepti
- Solve MySQL table can not query, modify, delete and other operations and appear stuck
- [Solved] java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corres
- Error 1418 (HY000): this function has none of deterministic, no SQL
- Bulk Update Error: #Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the m
- java.sql.SQLException: Disk full (/tmp/#sql_1eaa2_60.MAI); waiting for someone to free some space
- [Linux Docker Mirror] MYSQL Run sql Script Error: Failed to open file ‘/home/mydatabase.sql‘, error: 2
- C# System.Data.SQLite.SQLiteException:“SQL logic error or missing database no such table: XX”
- Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 – Connection is not available, request timed out after 30005ms.
- [Solved] SQL Error: Method queryTotal execution error of sql
- [Modified] Hive SQL Error: SQL ERROR [10004] [42000]: Error while compiling statement: FAILED: SemanticException [Error
- [Solved] Error: read ECONNRESET at TCP.onStreamRead Cannot enqueue Query after fatal error
- ORA-29913 ORA-06512 external table query prompt: error
- [Solved] Error Code: 2013. Lost connection to MySQL server during query
- [Mybatis] How to Solve the problem of Oracle query processing more than 1000 in conditions
- Navicat connecting to SQL Server Error [How to Solve]
- Can mybatis prevent SQL injection
- SQL editor and reconnect [an exception when MySQL (workbench) updates data] [error code: 1175]