Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The Microsoft Jet database engine cannot open the file It is already opened exclusively by another user, or you need permission to view its data.

This Error Disply after Handling The Code BY Using

C#
string f = fu.PostedFile.FileName;
      
       string fileType = f.Split('.')[1];

        OleDbConnection excelCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + f + ";Extended Properties=Excel 8.0");

        if (excelCon.State == ConnectionState.Closed)
        {
            excelCon.Open();
        }
        
        OleDbCommand excelCom = new OleDbCommand("SELECT * FROM [Sheet1$]", excelCon);
        OleDbDataAdapter excelAdp = new OleDbDataAdapter(excelCom);
        DataSet excelDs = new DataSet();
        excelAdp.Fill(excelDs);
        
        gvSending.DataSource = excelDs.Tables[0];
        gvSending.DataBind();

        excelCon.Close();
Posted
Updated 14-Jul-13 10:47am
v2
Comments
[no name] 13-Jul-13 11:17am    
"It is already opened exclusively by another user" you need to find out what else has the file open.
CHill60 13-Jul-13 12:49pm    
Do you have the file open in Excel? If not, when you closed it are you sure it closed properly? For example if you open Task Manager and look at the Processes tab can you see Excel.exe?
ZurdoDev 13-Jul-13 22:18pm    
Something else has the file open. Close it first.
zkuzet 14-Jul-13 17:44pm    
Maybe the problem is with the Office DLLs in your machine. Please try executing your project on a different machine...

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