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

34 comments :

Anonymous said...

Hai sir,

i did same, but i am getting same error sir

Unknown said...

sir,

i did same, but i am getting same error sir

Unknown said...

SORRY SIR ITS STILL NOT WORKING

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

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

Unknown 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

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

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

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

tser said...

hi my error 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.

plz help me soon

tser said...

please help me soon am waiting suresh ,sir
please

Unknown said...

hope it will help you.
string path = Server.MapPath(UploadExcelFile.PostedFile.FileName);

Unknown said...

Sorry sir it is not working..

Anonymous said...

Thnk u mr. santosh

MG said...

System.Data.OleDb.OleDbException: Server connection error in my application. I am getting this error in Visual Studio 2012 c# asp.net aspx page. The Microsoft Office Access database engine could not find the object xls.
conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FullPath + ";Extended Properties=\"HTML Import\""; Thanks Mr. Suresh, your tutorials are quite good.

Anonymous said...

STILL it is not working sir....please provide the resolution

David Ortega M said...

i have a problem with the postback, all works fine but dont show the grid with data says: "no file selected" but i put breakpoints and the grid has data nut sont show it in the postback.

Thanks for the help.

Hakim Chandio said...

its not working :/

Hari Shankar Maurya said...

Hi sir i am getting this error

The Microsoft 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.

Anonymous said...

so what is the solution to this error

Unknown said...

Hi sir i am still getting this error

The Microsoft 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

Unknown said...

on "Advance Security Settings" click Share tab. click add. click object type. include computer. click OK. Under 'Enter the object name to select' add the name of the computer your using to access the file. then click 'OK'. then apply.

Anonymous said...

Thank you. it works fine.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 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.