Skip to content
Amal Hashim
All posts
Article

OleDbConnection - Unspecified error

Fix the unspecified error from OleDbConnection.Open when reading Excel files on SharePoint 2010 with the ACE provider.

1 min read#.NET#Office#SharePoint 2010

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.

  1. Install the latest Microsoft Access Database Engine (the ACE OLEDB provider). Pick the correct platform, 32 bit or 64 bit, to match your application.
  2. Use this connection string:
text
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=fileLocation;Extended Properties="Excel 12.0 Xml;HDR=Yes;IMEX=1"
  1. Turn off impersonation in the web.config file:
xml
<identity impersonate="false" />

What the connection string options do

  • HDR=Yes means the first row of the sheet is a header row.
  • IMEX=1 forces cells to be read as text rather than the Excel General type, which converts the data.