Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.


What may be the cause for this?

[EDIT]
This was my code:
C#
SqlConnection con=new SqlConnection();
       con.ConnectionString  = ConfigurationManager.ConnectionStrings["db"].ToString();
       con.Open();
        string path = fileuploadExcel.PostedFile.FileName;
       
       string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

        OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
        excelConnection.Open();
        OleDbCommand cmd = new OleDbCommand("Select [Question],[Choice1],[Choice2],[Choice3],[Choice4],[Ans],[Category] from [Sheet1$]", excelConnection);
       
OleDbDataReader dReader;
dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(con);
 

    sqlBulk.ColumnMappings.Add("Question", "Qn");
    sqlBulk.ColumnMappings.Add("Choice1", "option1");
    sqlBulk.ColumnMappings.Add("Choice2", "option2");
 
    sqlBulk.ColumnMappings.Add("Choice3", "option3");
    sqlBulk.ColumnMappings.Add("Choice4", "option4");
    sqlBulk.ColumnMappings.Add("Ans", "ans");
    sqlBulk.ColumnMappings.Add("Category", "Q_Type");
    sqlBulk.DestinationTableName = "Questions";
    sqlBulk.WriteToServer(dReader);

excelConnection.Close();

[/EDIT]
Above content comes from OP's comment - Maciej Los
Posted
Updated 9-May-14 0:31am
v2
Comments
Sunasara Imdadhusen 9-May-14 5:50am    
Can you please provide code snippet so it will help us to understand your question clearly.
Prasad Avunoori 9-May-14 6:02am    
Has the excel file opened already?
KALYANI BIBIN 9-May-14 6:03am    
no excel file is not opened .
KALYANI BIBIN 9-May-14 6:06am    
--the content has been moved to the question --
Maciej Los
[no name] 9-May-14 6:12am    
before you submit data try to close all opened excel sheet

1 solution

Its working for this path : C:\Program Files (x86)\Common Files\microsoft shared\DevServer

Means you need to follow

You need to remove Read Only Check box check from properties of your folder and if that also doesn't work try to make that Drive allow permission for your particular path allowed to full control in user permissions in properties.
 
Share this answer
 
Comments
KALYANI BIBIN 10-May-14 0:44am    
Sorry not getting..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900