Microsoft Access数据库引擎无法打开或写入文件''。它已由其他用户独占打开,或者您需要获得查看和写入其数据的权限。 [英] 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.

查看:322
本文介绍了Microsoft Access数据库引擎无法打开或写入文件''。它已由其他用户独占打开,或者您需要获得查看和写入其数据的权限。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了Microsoft AccessDatabaseEngine 2010.之后我不做任何事情......因为我对oledb连接一无所知......然后我执行下面的文件然后我收到以下错误... Microsoft Access数据库引擎无法打开或写入文件''。它已经由另一个用户专门打开,或者您需要获得查看和编写其数据的权限 ......我该如何解决...任何人都会帮助我...如果有任何步骤参与oledb连接然后显示步骤请..........



Aspx文件:

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>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <p>
        <br />
    </p>
<div>
<table>
<tr>
<td>
<span style="color: Red">*</span>Attach Excel file
</td>
<td>
<asp:FileUpload ID="fileuploadExcel" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Export" onclick="btnSend_Click"  />
</td>
</tr>
</table>
<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" />
</asp:GridView>
</div>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
</asp:Content>



Aspx.cs文件:


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);
        excelConnection.Open();
        OleDbDataReader dReader;
        dReader = cmd.ExecuteReader();
        SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
        //Give your Destination table name
        sqlBulk.DestinationTableName = "exportcheckTB";
        sqlBulk.WriteToServer(dReader);
        excelConnection.Close();
    }
}



Web.config文件:


Web.config file :

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

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

  <system.web>
    <compilation debug="true" targetframework="4.0" />

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

    <membership>
      <providers>
        <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="/" />
      </add></providers>
    </membership>

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

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

  </system.web>

  <system.webserver>
     <modules runallmanagedmodulesforallrequests="true" />
  </system.webserver>
</configuration>

推荐答案

,excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
// 提供目的地表名称
sqlBulk.DestinationTableName = exportcheckTB;
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}
}
", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); //Give your Destination table name sqlBulk.DestinationTableName = "exportcheckTB"; sqlBulk.WriteToServer(dReader); excelConnection.Close(); } }



Web.config文件:


Web.config file :

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

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

  <system.web>
    <compilation debug="true" targetframework="4.0" />

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

    <membership>
      <providers>
        <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="/" />
      </add></providers>
    </membership>

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

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

  </system.web>

  <system.webserver>
     <modules runallmanagedmodulesforallrequests="true" />
  </system.webserver>
</configuration>


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


这篇关于Microsoft Access数据库引擎无法打开或写入文件''。它已由其他用户独占打开,或者您需要获得查看和写入其数据的权限。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆