Vidual Studio 2017 C# System.Data.OleDb cannot read newer Excel files

0

I use Visual Studio Professional 2017 (15.9.16 and .NET Framework 4.7.02558), coding in C#.

I have existing code using System.Data.OleDB that successfully reads older Excel files, but newer ones fail to be read, getting the error "external table is not in the expected format". Full exception is shown at the end of this post.

I claim this is a version problem because if I down-convert the file to, say, Excel 2003, then reading the workbook succeeds. The only difference being the version of the Excel file.

I've done some initial poking around hoping to find that I merely need upgrade some component in Visual Studio, but I have not had luck in this respect; there are so many pieces to this puzzle I don't know where to begin.

System.Data.OleDb.OleDbException
HResult=0x80004005
Message=External table is not in the expected format.
Source=System.Data
StackTrace:
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
c#
excel
oledb
oledbconnection
asked on Stack Overflow Feb 3, 2020 by BinaryBob

1 Answer

0

OK I have come across the proper solution. Instead of OleDb, I should be using OpenXML (DocumentFormat.OpenXML). I am getting myself up-to-speed on this approach now

answered on Stack Overflow Feb 3, 2020 by BinaryBob

User contributions licensed under CC BY-SA 3.0