Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel 2007 DataSource connection error in Visual Studio 2008 unit test
    primarykey
    data
    text
    <p>I am trying to use an Excel 2007 as a data source in my VS 2008 Test Project a unit test.</p> <p>Config file:</p> <pre><code>&lt;configuration&gt; &lt;configSections&gt; &lt;section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&gt; &lt;/configSections&gt; &lt;connectionStrings&gt; &lt;add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=SearchTestValues.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" /&gt; &lt;/connectionStrings&gt; &lt;microsoft.visualstudio.testtools&gt; &lt;dataSources&gt; &lt;add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/&gt; &lt;/dataSources&gt; &lt;/microsoft.visualstudio.testtools&gt; &lt;/configuration&gt; </code></pre> <p><strong>My Test Code:</strong></p> <pre><code>[TestMethod] [DeploymentItem("SearchTestValues.xlsx")] [DataSource("MyExcelDataSource")] public void ShouldReturnResultsValidity() { var minDate = (DateTime)TestContext.DataRow["MinDate"]; var maxDate = (DateTime)TestContext.DataRow["MaxDate"]; var minStatus = (int)TestContext.DataRow["MinStatus"]; var maxStatus = (int)TestContext.DataRow["MaxStatus"]; var criteria = new SearchCriteria(minDate, maxDate, minStatus, maxStatus); Assert.IsTrue(criteria.IsValid()); } </code></pre> <p>The excel file is in the root folder of the project. The file <em>BuildAction</em> is set to Content and <em>Deploy</em> is set to copy if newer. I also added the file to the list of Deployment Items so the excel file is deployed to the out folder of the TestResults folder when the test is run.</p> <p>When I run this test, here is the error I get:</p> <pre><code>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. </code></pre> <p>Any ideas why I am getting this error?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload