MSOLEDBSQL Causes Error 3706: Provider Cannot Be Found

BDr*_*Dra 4 sql excel vba connection-string

A client has for many years been using an Excel VBA application to interact with a SQL database. Recently the database has been upgraded from TLS 1.0 to TLS 1.2, which caused the connection from VBA to fail, as the SQLOLEDB driver has been deprecated. (Background here and here.)

To resolve the issue, I am trying to change the SQL driver from SQLOLEDB to MSOLEDBSQL. However, attempting to connect to the DB triggers run-time error 3706: "Provider cannot be found. It may not be properly installed."

Here is the relevant code:

Dim conn As ADODB.Connection
Dim sConnString As String
 
sConnString = "Provider=MSOLEDBSQL;" & _
  "Data Source=MyServerName;" & _
  "Initial Catalog=MyDBName;" & _
  "User ID=SomeID;" & _
  "Password=SomePassword;" & _
  "DataTypeCompatibility=80"

Set conn = New ADODB.Connection
conn.Open sConnString
Run Code Online (Sandbox Code Playgroud)

All instructions I have found online say to simply install the MSOLEDBSQL driver from Microsoft and change Provider=SQLOLEDB to Provider=MSOLEDBSQL in the code. But as I keep getting error 3706, presumably I must have missed a step.

Steps taken so far:

  1. Installed 32-bit MSOLEDBSQL driver from Microsoft.
  2. Confirmed that DLL files have been added to the default location, C:\Windows\System32.
  3. Restarted Windows.
  4. From the command line, ran REGSVR32 "C:\Windows\System32\msoledbsql19.dll". Windows confirmed that the resource had been correctly registered.
  5. In Visual Basic Editor, added a reference to Microsoft ActiveX Data Objects 6.1 Library (and removed a reference to the older v. 2.8 library).

Is it conceivable that the driver has not been properly installed, as claimed in the error description, when Windows also confirms that it has been correctly registered? How do I even troubleshoot this? Any thoughts on what is going on here?

BDr*_*Dra 6

在数据库管理员的宝贵帮助下,我们能够查明并解决错误。事实证明它非常简单。

MSOLEDBSQL 驱动程序的最新版本 v.19 引入了一些重大更改,其中之一是默认打开加密。微软承认这是一个“向后兼容破坏”的改变。他们在这里讨论这些变化及其原因。

连接字符串的此修订版本有效:

Dim conn As ADODB.Connection
Dim sConnString As String
 
sConnString = "Provider=MSOLEDBSQL19;" & _
   "Data Source=MyServerName;" & _
   "Initial Catalog=MyDBName;" & _
   "User ID=SomeID;" & _
   "Password=SomePassword;" & _
   "Use Encryption for Data=False;" & _
   "DataTypeCompatibility=80"

Set conn = New ADODB.Connection
conn.Open sConnString
Run Code Online (Sandbox Code Playgroud)

唯一重要的变化是Use Encryption for Data=False需要指定。