0

I am trying to manipulate an excel 2010 file in my asp net mvc application.

This is the code:

string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\teste.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
OleDbConnection conexao = new OleDbConnection(connectionString);
conexao.Open();

Open() method trows an exception I cannot find out why.

Exception:

    Erro: System.Data.OleDb.OleDbException (0x80004005): Failure creating file.
   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& connection)
   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()
   at Gedi.Controllers.AdminController.File() in c:\Users\Guilherme\Documents\Visual Studio 2012\Projects\Gedi\Gedi\Controllers\AdminController.cs:line 62
1
  • Is the file opened at the same time you are accessing it? Commented Jan 9, 2013 at 16:16

1 Answer 1

2

Use a variable fro the file-path with a verbatim string:

string path = @"c:\teste.xlsx";
string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";");", path);

Otherwise you need to mask the backslashes like "c:\\teste.xlsx":

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.