RedEagle
RedEagle

Reputation: 4560

External table is not in the expected format

I'm developing an Web Application (C#) on a Windows 7 Enterprise (x64), with Office 2007 using Visual Web Developper 2010 Express. On that project that reads information from Excel files like so:

protected void Page_Load(object sender, EventArgs e)
    {
      string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\1.xlsx;Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"";
      OleDbConnection oleDbConn = new OleDbConnection(connString);
      try
      {
        oleDbConn.Open();
        OleDbCommand oleDbComm = new OleDbCommand("SELECT * FROM [Sheet1$]", oleDbConn);
        OleDbDataAdapter oleDbDtAdapter = new OleDbDataAdapter();
        oleDbDtAdapter.SelectCommand = oleDbComm;         
        oleDbConn.Close();
      }
      catch (Exception evt)
      {
        Response.Write("ERRO: " + evt.Message.ToString());
      }
    }

On the development PC everything works as it should and I am able to open both XLS and XLSX Files.

Now, passing this simple code to my deployment server wich has Windows Server 2003 R2 Standard X64 Edition (SP2) I had to install Access Database Engine 2007 (only for x86) since there was no Office 2007 on the server, so after the instalation, and deploying this simple code to the server I got IErrorInfo.GetDescription failed with E_FAIL(0x80004005) error.

Some more searching and I found out that there was an Access Database Engine 2010, this time for bot x86 and x64 architectures so I thought duuhhh now It's gona work.

After installing Access Database Engine 2010 voila I was able to access XLS file but for XLSX I'm now getting this crazy error:

External table is not in the expected format

I've been banging my head for almost a day now, but still can't understand why this is happening!

Upvotes: 0

Views: 5093

Answers (2)

jordanhill123
jordanhill123

Reputation: 4182

I had this same issue on a local pc (Using the ACE.OLEDB) and what resolved it for me was this link:

http://support.microsoft.com/kb/2459087

The gist of it is that installing multiple office versions and various office sdk's, assemblies, etc. had led to the ACEOleDB.dll reference in the registry pointing to the OFFICE12 folder instead of OFFICE14 in

C:\Program Files\Common Files\Microsoft Shared\OFFICE14\ACEOLEDB.DLL

From the link:

Alternatively, you can modify the registry key changing the dll path to match that of your Access version.

Access 2007 should use OFFICE12, Access 2010 - OFFICE14 and Access 2013 - OFFICE15

(OS: 64bit Office: 64bit) or (OS: 32bit Office: 32bit)

Key: HKCR\CLSID{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32\

Value Name: (Default)

Value Data: C:\Program Files\Common Files\Microsoft Shared\OFFICE14\ACEOLEDB.DLL

(OS: 64bit Office: 32bit)

Key: HKCR\Wow6432Node\CLSID{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32\

Value Name: (Default)

Value Data: C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\ACEOLEDB.DLL

Upvotes: 0

steffen
steffen

Reputation: 11

I fixed the "External table is not in the expected format" error by installing Microsoft Office Access Runtime and Data Connectivity 2007 Service Pack 2 (SP2)

Upvotes: 1

Related Questions