c# - Error using Data Source relative path in Excel Data Driven Unit Test -


i using system.data.odbc connection string connect excel data source. following error occurs when using relative dbq path:

error [42s02] [microsoft][odbc excel driver] microsoft office access database engine not find object 'sheet1$'. make sure object exists , spell name , path name correctly.

app.config:

<configuration>     <configsections>         <section name="microsoft.visualstudio.testtools" type="microsoft.visualstudio.testtools.unittesting.testconfigurationsection, microsoft.visualstudio.qualitytools.unittestframework, version=10.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"/>     </configsections>     <connectionstrings>         <add name="excelconnection" connectionstring="dsn=excel files;dbq=exceldatasource.xlsx;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5" providername="system.data.odbc"/>     </connectionstrings>     <microsoft.visualstudio.testtools>         <datasources>             <add name="exceldatasource" connectionstring="excelconnection" datatablename="sheet1$" dataaccessmethod="sequential"/>         </datasources>     </microsoft.visualstudio.testtools> </configuration> 

test method attributes:

[deploymentitem("exceldatasource.xlsx")] [datasource("exceldatasource")] [testmethod] 

troubleshooting notes:

  • works absolute dbq path
  • excel file set 'copy if newer' , [deploymentitem] specified
  • fails before reaching [testinitialize] method; before test deployment dir created.
  • it worked in past, perhaps in older visual studio version

question: defaultdir=.; resolve to?

it resolved correctly using |datadirectory| variable: defaultdir=|datadirectory|.

connectionstring="dsn=excel files;dbq=exceldatasource.xlsx;defaultdir=|datadirectory|\;driverid=790;maxbuffersize=2048;pagetimeout=5" 

more on |datadirectory| variable here


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -