OleDbConnection - Unspecified error
Fix the unspecified error from OleDbConnection.Open when reading Excel files on SharePoint 2010 with the ACE provider.
While building an Excel parser on SharePoint 2010, I hit a strange "Unspecified error". The exception came from OleDbConnection.Open, with no inner exception and no useful stack trace, so the root cause was hard to find.
Uninstalling Office and restarting IIS did not help. Three steps fixed it.
- Install the latest Microsoft Access Database Engine (the ACE OLEDB provider). Pick the correct platform, 32 bit or 64 bit, to match your application.
- Use this connection string:
text
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=fileLocation;Extended Properties="Excel 12.0 Xml;HDR=Yes;IMEX=1"
- Turn off impersonation in the web.config file:
xml
<identity impersonate="false" />
What the connection string options do
HDR=Yesmeans the first row of the sheet is a header row.IMEX=1forces cells to be read as text rather than the Excel General type, which converts the data.