By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

Problem opening OleDB Excel connection

P: 1
I have several Excel files which I need to import into a SQL server. I open each file using
Expand|Select|Wrap|Line Numbers
  1. string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  2. "Data Source = " + fileName + ";Extended Properties=\"Excel 8.0;HDR=No\"";
  3. OleDbConnection conn = new OleDbConnection(connectionString);
  4. conn.Open();
This works for a lot of the files, but apparently some of the files, it can't open throw'ing the following exception:
Expand|Select|Wrap|Line Numbers
  1. System.Data.OleDb.OleDbException was unhandled
  2.   Message="Filen kan ikke dekrypteres."
  3.   Source="Microsoft JET Database Engine"
  4.   ErrorCode=-2147467259
  5.   StackTrace:
  6.        at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
  7.        at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
  8.        at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
  9.        at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
  10.        at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
  11.        at System.Data.OleDb.OleDbConnection.Open()
  12.        at Converter.ImportExcel.Import(String fileName) in ... BLA BLA
This is on a WindowsXP machine, in Visual Studio 2005 (.NET2.0). As i said, it works for some of the files but some doesen't work.

Now the really strange part is: If i open the file in Excel2007 pre activating the above code, it runs without the exception. When i close the file in Excel2007 again, and re-run, it throws the exception again.

Apr 25 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.