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

发布于 2024-08-29 16:54:16 字数 963 浏览 1 评论 0原文

我有一个应用程序最初需要连接到 Sybase(通过 ODBC),但我还需要添加连接到 SQL Server 的功能。由于 ODBC 应该能够处理这两种情况,所以我认为我处于一个很好的位置。

不幸的是,默认情况下,SQL Server 不会让我嵌套 ODBC 命令和 ODBCDataReaders - 它抱怨连接正忙(连接正忙于处理另一个命令的结果)。

我知道当通过本机驱动程序连接到 SQL Server 时,我必须指定在类似情况下允许多个活动结果集 (MARS),因此我认为这不会成为问题。

DSN 向导没有输入 y 创建 SystemDSN 时。

有些人提供了注册表破解来解决此问题,但这不起作用(将值为 Yes 的 MARS_Connection 添加到 HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\system-dsn-name)。

另一个建议是创建一个文件 dsn,并向其中添加“MARS_Connection=YES”。没用。

最后,一个无 DSN 的连接字符串。我已经尝试过这个(使用 MultipleActiveResultSets - 与 Sql Server 连接使用的变量相同),

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

还有这个:

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

我检查了各种连接字符串站点 - 它们都建议我已经尝试过的内容。

我应该声明我已经尝试过 SQL Server 驱动程序和 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. As ODBC should be able to handle both, I thought I was in a good position.

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).

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.

The DSN wizard has no entr
y when creating a SystemDSN.

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).

Another suggestion was to create a file-dsn, and add "MARS_Connection=YES" to that. Didn't work.

Finally, a DSN-less connection string. I've tried this one (using MultipleActiveResultSets - same variable as a Sql Server connection would use),

"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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒尘 2024-09-05 16:54:16

根据 SNI 文档 使用多个活动结果套装(火星)

SQL Server Native Client ODBC
驱动程序通过添加支持 MARS
到 SQLSetConnectAttr 和
SQLGetConnectAttr 函数。
SQL_COPT_SS_MARS_ENABLED 已
添加以接受任一
SQL_MARS_ENABLED_YES 或
SQL_MARS_ENABLED_NO,带有
SQL_MARS_ENABLED_NO 是默认值。
此外,还有一个新的连接字符串
关键字 Mars_Connection,如前所述
额外。它接受“是”或“否”
价值观; “否”是默认值

确保您的客户端加载正确的驱动程序,使用 Mars_Connection=yes,并通过检查 SQLGetConnectAttr

According to the SNI documentation on Using Multiple Active Result Sets (MARS):

The SQL Server Native Client ODBC
driver supports MARS through additions
to the SQLSetConnectAttr and
SQLGetConnectAttr functions.
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.
In addition, a new connection string
keyword, Mars_Connection, as been
added. It accepts "yes" or "no"
values; "no" is the default
.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文