Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio 2008单元测试中的Excel 2007数据源连接错误_C#_Visual Studio 2008_Unit Testing - Fatal编程技术网

C# Visual Studio 2008单元测试中的Excel 2007数据源连接错误

C# Visual Studio 2008单元测试中的Excel 2007数据源连接错误,c#,visual-studio-2008,unit-testing,C#,Visual Studio 2008,Unit Testing,我正在尝试使用Excel2007作为VS2008测试项目单元测试的数据源 配置文件: <configuration> <configSections> <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Micr

我正在尝试使用Excel2007作为VS2008测试项目单元测试的数据源

配置文件:

<configuration>
    <configSections>
        <section name="microsoft.visualstudio.testtools"
                 type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </configSections>
    <connectionStrings>
        <add name="MyExcelConn"
             connectionString="Dsn=Excel Files;dbq=SearchTestValues.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5"
             providerName="System.Data.Odbc" />
    </connectionStrings>
    <microsoft.visualstudio.testtools>
        <dataSources>
            <add name="MyExcelDataSource"
                 connectionString="MyExcelConn"
                 dataTableName="Sheet1$"
                 dataAccessMethod="Sequential"/>
        </dataSources>
    </microsoft.visualstudio.testtools>
</configuration>
excel文件位于项目的根文件夹中。文件BuildAction设置为Content,Deploy设置为copy(如果较新)。我还将该文件添加到部署项列表中,以便在测试运行时将excel文件部署到TestResults文件夹的out文件夹中

当我运行此测试时,以下是我得到的错误:

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 [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Office Access database engine could not find the object 'Sheet1$'.  Make sure the object exists and that you spell its name and the path name correctly.
你知道我为什么会犯这个错误吗

谢谢

试试看

dataTableName="[Sheet1$]"

我们也有同样的问题。我们试图改变驱动程序、配置等


当然,将Excel电子表格保存为97-2003兼容(a.xls而不是a.xlsx)可以解决这个问题。不确定这在您的情况下是否可行。

要解决此问题,您必须更改Excel文件的属性

构建操作:内容 复制到输出目录:如果较新,则复制


那它就应该起作用了

我在使用mstest.exe部署测试时遇到了相同的问题-在目标计算机上安装VS 2008为我修复了它

没用。这次错误是:单元测试适配器未能连接到数据源或读取数据。有关此错误的疑难解答的详细信息,请参阅MSDN库中的“数据驱动单元测试疑难解答”()。错误详细信息:错误[42000][Microsoft][ODBC Excel驱动程序]名称“[Sheet1$”的括号无效。为了确保这一点,我将dataTableName完全修改为“[Sheet1$”,但错误消息似乎遗漏了右括号。然而,它不起作用。
dataTableName="[Sheet1$]"