我有一个如下所示的python脚本,可以连接服务器的数据库并获取数据
db = QtSql.QSqlDatabase.addDatabase('QODBC')
db.setDatabaseName("DRIVER={SQL Server};SERVER=myservername;DATABASE=master;Trusted_Connection=yes")
db.open()
with open(QueryFile , "r") as readQuery:
queryText = readQuery.read()
readQuery.close()
query = QtSql.QSqlQuery()
query.exec_(queryText)
while query.next():
for i in range (query.record().count()):
temp_list.append(query.value(i))
queryResultList.append(temp_list[:])
del temp_list[:]
db.close()
当我执行声明设置变量的查询时,会出现如下错误
USE myDB
Declare @M as integer
set @M= 3
Select top 1000 Position.latitude,
Position.longitude,
data
from mydatas,Position
where mydatas.data > @M
“ QODBCDriver :: disconnect:无法断开数据源”错误: “ [Microsoft] [ODBC SQL Server驱动程序] [共享内存] ConnectionClose (closesocket())。 “ QODBCDriver :: cleanup:无法释放连接 句柄”“ QODBCDriver :: cleanup:无法释放环境句柄”
错误:“ [Microsoft] [ODBC驱动程序管理器]...。”
但是当我注释掉set @M=3
行并在where子句中将@M
的值更改为3时:
USE myDB
Declare @M as integer
--set @M= 3
Select top 1000 Str(Position.latitude, 13, 13),
Str( Position.longitude, 13, 13),
Str(data)
from dbo.mydatas,Position
where mydatas.data > 3
它按预期工作,这是什么问题?