Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - 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

Jan 18, 2013
Introduction:

Here I will explain “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.” problem solution in asp.net using C# and VB.NET.

Description:

In previous articles I explained Import/upload data from excel to gridview in asp.net, Export selected rows of gridview to excel/word document, Export gridview data to pdf in asp.net and many articles relating to Excel, Gridview, SQL ,jQuery,asp.net, C#, VB.NET. Now I will explain how to solve the problem of “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.” in asp.net using C# and VB.NET.

In one application I got requirement like Read or Import data from excel sheet to gridview and upload excel data to SQL database once implementation completed I tested it in local everything working fine. After I deployed application in server machine and tried to run then I got an error like "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”. 

To solve this problem we need to grant the NETWORK SERVICE account modify permission on my folder where our excel files will sit for that follow below steps.
 
     1.    Select your folder >> Right click on folder and select properties like as shown below 

 
     2.    Once properties opened >> Select Security Tab >> In that click on Edit button to change the permissions like as shown below

     3.    Once you click on Edit button another window will open in that select Add button like as shown below

     4.    Now click on Add button >> Another window will open in that enter “Network Service” as name >> click on Check Names like as shown below

     5.    Once “Network Service” added set permissions for Network Service and click ok like as show below

Once set network service permissions run your application i hope this will fix your problem.

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

20 comments :

Anonymous said...

Hai sir,

i did same, but i am getting same error sir

Sandhya Vani said...

sir,

i did same, but i am getting same error sir

Yogesh Gautam said...

SORRY SIR ITS STILL NOT WORKING

narvesh kumar said...

sorry sir but its not working

Anonymous said...

Hi Suresh,

I am getting this error , please help me

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

Atif Ali said...

Hi All,
You will definitely get this error since the file is posted on file upload control it is used by it ... so it says 'opened exclusively'.The solution is that u first save the file on server then read it.

Anonymous said...

but how to set permission programmatically ?

Harris said...

HI,

I am trying to access MDB files placed on remote machines from a central server where SQL is running and it is giving me same error. What should i do?

vinobabur said...

SIR i'M GETTING SAME ERROR..

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.

handaru eri pramudiya said...

sir how to fix it ? its still error , i need your help . Thank you sir

Anonymous said...

Sir, still the same error.

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.

Vipasha Sen said...

For "network service" select and save modify right also and you all won't get any error further.

MAHI said...

If you follow above process still getting the error, The problem is with the File Upload Control.
If we take path of the file to be uploaded as below
Fileupload1..PostedFile.FileName;
it is generating the error.

If we replace the Path manually(i.e. DataSource="c:\sample.xlsx" ) able to execute.

Anonymous said...

first u reply for these problems then will give a valuable feed back

pradeepkumar bunny said...

Dear fri,

I am also getting same error. pl give me the solution. it urgent for me..i am waiting any one can reply fast.

Rajkumar Patro said...

protected void btnImport_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~/App_Data/") + fileuploadExcel.FileName;
fileuploadExcel.SaveAs(path);
string a = fileuploadExcel.PostedFile.FileName;

OleDbConnection con_excel = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 8.0");

OleDbDataAdapter adpt = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", con_excel);
DataSet ds = new DataSet();
adpt.Fill(ds, "tbl_temp");

grvExcelData.DataSource = ds.Tables["tbl_temp"];
grvExcelData.DataBind();
}



After this code you need not to do anything else

Anonymous said...

Hi, with your above code the excel sheet is being displayed in my webpage in the gridview but is not getting inserted into my database. How do i get the data to my table in database?

Anonymous said...

My problem is with access not excel

Anonymous said...

Very helpful, my issue with access is solved by giving even modify rights to network service,

Thank u very much....

VS Mani said...

"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."

Please suggest me a proper solution for this problem, I had tried a lot but didn't found solution for this error.

In my PC only .how to resolve it. other PC's it works fine.

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.