英文:
Pyodbc can't enable MARS even when SQL native client shows 'MARS: yes'
问题
我正在尝试连接到一个启用了MARS的SQL Server 2019。首先,我在ODBC数据源中配置了一个系统DSN,显示MARS已启用(ODBC驱动程序17)。我还尝试了SQL Server本机客户端11.0,结果相同。
然后,我使用以下代码在pyodbc中创建了一个连接。
cnxn = pyodbc.connect(DSN="83something",
UID="something", PWD="something")
how_many = cnxn.getinfo(pyodbc.SQL_MAX_CONCURRENT_ACTIVITIES)
print('how many ', how_many)
然而,我仍然得到1,这表明对Pyodbc未启用MARS。我已经苦苦挣扎了很长时间,任何帮助都会感激。
我还尝试了在连接字符串中使用MARS_Connection = yes
,但不认为这在Windows上会起作用。
英文:
I am trying to connect to a SQL Server 2019 with MARS. First I have configured a system DSN in ODBC Data Sources, which shows MARS is enabled (ODBC driver 17). I have also tried SQL Server native client 11.0, which gives the same result.
Then I used this to create a connection in pyodbc.
cnxn = pyodbc.connect(DSN="83something",
UID="something",PWD="something")
how_many = cnxn.getinfo(pyodbc.SQL_MAX_CONCURRENT_ACTIVITIES)
print('how many ',how_many)
However I am still get 1, which indicates MARS is not enabled for Pyodbc. I have been struggling for a long time and any help is appreciated.
I have also tried MARS_Connection = yes in the connection string but don't think this will work on Windows.
答案1
得分: 0
我终于发现使用 MARS 设置 DSN 会有所帮助。即使最大并发显示为 1,实际上可以避免“光标忙”或类似的问题。
请参考以下步骤:
启动管理员命令提示符(例如,按下“开始”按钮,开始键入“命令提示符”,当它出现时,右键单击并选择“以管理员身份运行”)。
运行命令:odbcconf /a {CONFIGSYSDSN "SQL Server Native Client 11.0" "DSN=MY_DSN|MARS_Connection=Yes"}(用您自己的驱动程序和 DSN 名称替换驱动程序和 DSN 名称)。
您可以重新运行ODBC配置向导,现在应该会显示“Multiple Active Result Sets(MARS): YES”,而不是之前的“NO”。
如果您使用的是用户DSN,请使用CONFIGDSN而不是CONFIGSYSDSN。如果重新打开配置向导,您的更改应该是可见的;MARS选项(您无法编辑)应该已从“否”更改为“是”。
https://crateanon.readthedocs.io/en/latest/faq_troubleshooting.html#configure-odbc-mars
英文:
I finally find setting a DSN with MARS on helps. Even though MAX concurrent shows 1, it actually can avoid 'cursor busy' or something similar.
Please refer to the following steps:
Fire up an Administrator command prompt (e.g. press the Start button, start typing “Command Prompt”, and when it appears, right-click it and choose “Run as Administrator”).
Run the command: odbcconf /a {CONFIGSYSDSN "SQL Server Native Client 11.0" "DSN=MY_DSN|MARS_Connection=Yes"} (replacing the driver and DSN names with your own).
You can re-run the ODBC configuration wizard, and it should now say Multiple Active Result Sets(MARS): YES where it said … NO before.
Use CONFIGDSN instead of CONFIGSYSDSN if you are using a user DSN. Your changes should be visible if you reopen the configuration wizard again; the MARS option (which you can’t edit) should have changed from “No” to “Yes”.
https://crateanon.readthedocs.io/en/latest/faq_troubleshooting.html#configure-odbc-mars
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论