本地数据库上与Python和pyodbc的最大SQL连接数显示为1

问题描述

我目前正在学习如何建立本地Microsoft sql数据库,以期将来使其联机。

我的问题是关于一次允许的最大连接数。

#import required packages
import pyodbc

#define connection
conn = pyodbc.connect('connection string')

#create cursor
cursor = conn.cursor()
cursor2 = conn.cursor()

#check how many max connections available
how_many = conn.getinfo(pyodbc.sql_MAX_CONCURRENT_ACTIVITIES)
print(how_many)

我得到的答案是1。这是由于数据库是本地数据库还是因为我使数据库联机后会得到相同的答案?

即使我告诉我MS sql可以一次处理约32k个连接,但即使我选择了错误数据库类型,我也不想继续这样做。

下面我尝试查看最大值是否确实为2,一切正常,没有错误

#use cursor 1 to query the database
this = cursor.execute('select * from tablename')

#get all data from the table in the database
rows = this.fetchall()

#loop over rows and print each row to the terminal
for row in rows:
    print(row)

this2 = cursor2.execute('select * from tablename')
rows2 = this2.fetchall()
for row in rows2:
    print(row)

#commit the connection,close the cursors,close the connection
conn.commit()
cursor.close()
cursor2.close()
conn.close() 

这是测试的正确方法吗?这算作2个并发连接吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)