简体   繁体   English

在ODBC连接中打开多个结果集到SQL Server

[英]Turning on multiple result sets in an ODBC connection to SQL Server

I have an application that originally needed to connect to Sybase (via ODBC), but I've needed to add the ability to connect to SQL Server as well. 我有一个最初需要连接到Sybase(通过ODBC)的应用程序,但我还需要添加连接到SQL Server的功能。 As ODBC should be able to handle both, I thought I was in a good position. 由于ODBC应该能够处理两者,我认为我处于有利位置。

Unfort, SQL Server will not let me, by default, nest ODBC commands and ODBCDataReaders - it complains the connection is busy (Connection is busy with results for another command). 不幸的是,默认情况下,SQL Server不会让我嵌套ODBC命令和ODBCDataReaders - 它会抱怨连接繁忙(连接忙于另一个命令的结果)。

I know that I had to specify that multiple active result sets (MARS) were allowed in similar circumstances when connecting to SQL Server via a native driver, so I thought it wouldn't be an issue. 我知道在通过本机驱动程序连接到SQL Server时,我必须指定在类似情况下允许多个活动结果集(MARS),所以我认为这不是问题。

The DSN wizard has no entr y when creating a SystemDSN. 创建SystemDSN时,DSN向导没有任何内容。

Some people have provided registry hacks to get around this, but this did not work (add a MARS_Connection with a value of Yes to HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBC.INI\\system-dsn-name). 有些人提供了注册表黑客来解决这个问题,但这不起作用(向HKEY_LOCAL_MACHINE \\ SOFTWARE \\ ODBC \\ ODBC.INI \\ system-dsn-name添加值为Yes的MARS_Connection)。

Another suggestion was to create a file-dsn, and add "MARS_Connection=YES" to that. 另一个建议是创建一个文件-dsn,并为其添加“MARS_Connection = YES”。 Didn't work. 没工作。

Finally, a DSN-less connection string. 最后,一个无DSN的连接字符串。 I've tried this one (using MultipleActiveResultSets - same variable as a Sql Server connection would use), 我试过这个(使用MultipleActiveResultSets - 与Sql Server连接使用的变量相同),

"Driver={SQL Native Client};Server=xxx.xxx.xxx.xxx;Database=someDB;Uid=u;Pwd=p;MultipleActiveResultSets=True;"

and this one: 还有这个:

"Driver={SQL Native Client};Server=192.168.75.33\\ARIA;Database=Aria;Uid=sa;Pwd=service;MARS_Connection=YES;"

I have checked the various connection-string sites - they all suggest what I've already tried. 我检查了各种连接字符串网站 - 他们都建议我已经尝试过。

I should state that I've tried both the SQL Server driver, and the SQL Server native driver... 我应该说我已经尝试过SQL Server驱动程序和SQL Server本机驱动程序......

According to the SNI documentation on Using Multiple Active Result Sets (MARS) : 根据有关使用多个活动结果集(MARS)的SNI文档:

The SQL Server Native Client ODBC driver supports MARS through additions to the SQLSetConnectAttr and SQLGetConnectAttr functions. SQL Server Native Client ODBC驱动程序通过添加SQLSetConnectAttr和SQLGetConnectAttr函数来支持MARS。 SQL_COPT_SS_MARS_ENABLED has been added to accept either SQL_MARS_ENABLED_YES or SQL_MARS_ENABLED_NO, with SQL_MARS_ENABLED_NO being the default. 已添加SQL_COPT_SS_MARS_ENABLED以接受SQL_MARS_ENABLED_YES或SQL_MARS_ENABLED_NO,SQL_MARS_ENABLED_NO是默认值。 In addition, a new connection string keyword, Mars_Connection, as been added. 此外,添加了一个新的连接字符串关键字Mars_Connection。 It accepts "yes" or "no" values; 它接受“是”或“否”的值; "no" is the default . “no”是默认值

Make sure your client loads the right drivers, use Mars_Connection=yes , and validate in the app by checking SQL_COPT_SS_MARS_ENABLED on SQLGetConnectAttr . 确保您的客户端加载正确的驱动程序,使用Mars_Connection=yes ,并通过检查SQLGetConnectAttr上的 SQL_COPT_SS_MARS_ENABLED在应用程序中进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM