无法使用新的 MSOLEDBSQL 连接到 SQL Server 2019

问题描述 投票:0回答:1

我正在将我的应用程序转换为使用 SQL Server Native Client 11.0 中的 MSOLEDBSQL

我已将连接字符串从“Driver={SQL Server Native Client 11.0}”更改为“Provider=MSOLEDBSQL”以及 UID、PWD、服务器、数据库参数。

但是在使用 SQL_DRIVER_COMPLETE 时,我无法连接到数据库并收到“[Microsoft][ODBC Driver Manager] Dialog failed”错误消息。

IM008   Dialog failed   The driver attempted to display its login dialog box and failed.

WindowHandle was a null pointer, and DriverCompletion was not SQL_DRIVER_NO_PROMPT.

同样,当使用 SQL_DRIVER_NOPROMPT 时,它会抛出错误“[Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序”。

IM002   Data source not found and no default driver specified   (DM) The data source name specified in the connection string (InConnectionString) was not found in the system information, and there was no default driver specification.
(DM) ODBC data source and default driver information could not be found in the system information.

上述错误是由于调用 SQLDriverConnect() 而返回的。

我已经下载并安装了https://learn.microsoft.com/en-us/sql/connect/oledb/download-oledb-driver-for-sql-server?view=sql-server-ver15并且可以看到system32 文件夹中的二进制文件。

根据 MS Docs,注册表设置将作为安装的一部分完成。

All appropriate registry settings for the OLE DB Driver for SQL Server are made as part of the installation process. 
  1. 我们是否应该进行任何额外的注册表配置或其他设置才能使用 MSOLEDBSQL 驱动程序?

  2. 当我使用上面提到的 Driver 关键字时,它适用于本机客户端。但如果我使用“Provider=SQLNCLI11”,它就会失败。对此有什么想法吗?

我怀疑问题与加载驱动程序有关。

如果有人可以帮助解决此问题,请不胜感激。

提前致谢。

sql sql-server oledb sql-server-2019
1个回答
0
投票

我在使用 C++ 连接到 Azure SQL Server 时遇到了同样的错误。

检查您的连接字符串。

DRIVER={ODBC Driver 18 for SQL Server};Server=${HOST},${PORT};DATABASE=${DATABASE};UID=${USER};PWD=${PASSWORD};Authentication=SqlPassword;Encrypt=No

我必须关闭加密才能使 SqlPassword 身份验证正常工作。

然后按照官方文档此处中的建议使用 SQL_DRIVER_COMPLETE 标志而不是 SQL_DRIVER_NOPROMPT。

SQLDriverConnect(hDbc, nullptr, connStr, SQL_NTS, nullptr,
                                                            0, nullptr, SQL_DRIVER_COMPLETE);
© www.soinside.com 2019 - 2024. All rights reserved.