Visual Studio - 单元测试适配器无法连接到数据源或读取数据

Visual Studio - The unit test adapter failed to connect to the data source or to read the data

我正在尝试 运行 一些使用 Excel 电子表格作为数据源的单元测试,但我在 Visual Studio 2017 年收到以下错误:

Message: The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

测试方法属性为:

[TestMethod]
[DeploymentItem("SiteSettings.xml")]
[DeploymentItem("TestData\My_Test_Data.xls")]
[DeploymentItem("Drivers\IEDriverServer.exe", "Drivers")]
[DataSource("System.Data.Odbc", "Dsn=Excel Files; dbq=|DataDirectory|\My_Test_Data.xls", "MyApp$", DataAccessMethod.Sequential)]

同一个项目在其他两台机器上运行良好,在进一步调查后我发现 ODBC Data Source Administrator 中存在差异,可以通过转到 Control Panel -> Administrative Tools -> Data Sources (ODBC) 打开.在 User DSN tab 中,如果我 select Excel Files 并按下 Configure 按钮,我会陆续收到以下错误消息:

尝试 google 重新安装 Excel 驱动程序,但没有找到直接的方法。

OS: Windows 7 x64.

办公室:MS Office 365 (2016)。

Excel 数据文件的当前 ODBC 驱动程序是 Microsoft Access 数据库引擎 2016 Redistributable 的一部分,installers are freely downloadable from Microsoft。 (请注意,您必须在 32 位和 64 位安装程序之间进行选择。您可以下载两者并将它们安装在相同的 Windows 环境中。)

如果有人在安装 Office 365 时遇到此问题,那么安装 Microsoft Access Database Engine 2016 Redistributable 将无法正常工作。 Microsoft 建议为 Office 365 Click-to-运行 安装产品安装 Microsoft Access 2013 Runtime。 https://docs.microsoft.com/en-us/office/troubleshoot/access/cannot-use-odbc-or-oledb