Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am installed Microsoft AccessDatabaseEngine 2010. after that i dont do anything...because i dont know anything about oledb connection...... Then i am execute the below file then i am getting the following 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... ..... How can i solve that... Anyone help me please...If any steps are involved in oledb connection then show that steps please ..........

Aspx file :
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="UploadExcel_to_DB.aspx.cs" Inherits="UploadExcel_to_DB" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
        <br />
<span style="color: Red">*</span>Attach Excel file
<asp:FileUpload ID="fileuploadExcel" runat="server" />
<asp:Button ID="btnSend" runat="server" Text="Export" onclick="btnSend_Click"  />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4"
        ForeColor="#333333" GridLines="None" PageSize="30">
    <AlternatingRowStyle BackColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />

Aspx.cs File :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data.SqlClient;

public partial class UploadExcel_to_DB : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void btnSend_Click(object sender, EventArgs e)
        String strConnection = "Data Source=(local);Initial Catalog=MyDB;Integrated Security=True";
        //file upload path
        string path = fileuploadExcel.PostedFile.FileName;
        //Create connection string to Excel work book
        string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
        //Create Connection to Excel work book
        OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
        //Create OleDbCommand to fetch data from Excel
        OleDbCommand cmd = new OleDbCommand("Select [Business_ Name],[Category] from [Sheet1$]", excelConnection);
        OleDbDataReader dReader;
        dReader = cmd.ExecuteReader();
        SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
        //Give your Destination table name
        sqlBulk.DestinationTableName = "exportcheckTB";

Web.config file :
  For more information on how to configure your ASP.NET application, please visit

    <add name="ApplicationServices">
         connectionString="data source=Data Source=(local);Initial Catalog=MyDB;Integrated Security=True"
         providerName="System.Data.SqlClient" /&gt;

    <compilation debug="true" targetframework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />

        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionstringname="ApplicationServices">
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />

        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionstringname="ApplicationServices" applicationname="/" />

    <rolemanager enabled="false">
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionstringname="ApplicationServices" applicationname="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationname="/" />


     <modules runallmanagedmodulesforallrequests="true" />
Updated 5-Sep-17 2:08am
ZurdoDev 15-Mar-13 11:42am    
The error tells you what is happening. Someone has the file open.

1 solution

For your own sake, stop using access databases in multiuser environments. Look to use SQL server, or MySql instead - they are designed for multiuser operation in ways that access files are most definitely not.

When you use Access files directly in a website, you are running the risk that any other user can be trying to modify the file at the same time - and as a result you get an error. In your code it is even worse, because you are not disposing of the connection to the access file at all, so it will remain open until the garbage collector gets kicked in, or the session expires, whichever comes first.
Share this answer
SnvMohan 15-Mar-13 13:00pm    
Hello sir, i am using SQL server only for database.... I need to export the excel values into database-table....... How can i do that...?
Maciej Los 15-Mar-13 16:21pm    
Absolutly right!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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