Microsoft Office访问数据库引擎无法打开或写入该文件。该文件已由其他用户独占打开 [英] The Microsoft office access database engine cannot open or write to the file.it is already opened exclusively by another user

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

问题描述

我的代码如下



My code as follows

if (e.CommandName == "UploadFarmData")
{ 
string CurrentFilePath = Path.GetFullPath(FileUpload1.PostedFile.FileName);
constr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", CurrentFilePath);
Econ = new OleDbConnection(constr);
Econ.Open();
DataTable dtExcelSchema;
dtExcelSchema = Econ.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
DataSet ds = new DataSet();
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
OleDbCommand cmdExcel = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
da.SelectCommand = cmdExcel;
da.Fill(ds);
Econ.Close();
DataTable dt = new DataTable();
dt = ds.Tables[0];
bool s = false;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
dal.DAL_Insert_Farm_Data(dt.Rows[i]["Farmer Code"].ToString(), dt.Rows[i]["Farm No"].ToString(),
dt.Rows[i]["Type of Farm"].ToString(), dt.Rows[i]["Seeded Date"].ToString(), dt.Rows[i]["Farm Visit No"].ToString());
s = true;
}

if (s)
{
showStatusTrue.Style.Add("display", "block");
showStatusTrue.InnerHtml = "Farm Details Uploaded Successfully";
dal.DAL_Data_Update();
}
 
when i upload shows error as follows
 
 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

What I have tried:

<pre>
My code as follows

<pre> 
 
if (e.CommandName == "UploadFarmData")
{ 
string CurrentFilePath = Path.GetFullPath(FileUpload1.PostedFile.FileName);
constr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", CurrentFilePath);
Econ = new OleDbConnection(constr);
Econ.Open();
DataTable dtExcelSchema;
dtExcelSchema = Econ.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
DataSet ds = new DataSet();
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
OleDbCommand cmdExcel = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
da.SelectCommand = cmdExcel;
da.Fill(ds);
Econ.Close();
DataTable dt = new DataTable();
dt = ds.Tables[0];
bool s = false;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
dal.DAL_Insert_Farm_Data(dt.Rows[i]["Farmer Code"].ToString(), dt.Rows[i]["Farm No"].ToString(),
dt.Rows[i]["Type of Farm"].ToString(), dt.Rows[i]["Seeded Date"].ToString(), dt.Rows[i]["Farm Visit No"].ToString());
s = true;
}

if (s)
{
showStatusTrue.Style.Add("display", "block");
showStatusTrue.InnerHtml = "Farm Details Uploaded Successfully";
dal.DAL_Data_Update();
}
 
when i upload shows error as follows
 
 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

推荐答案

Quote:

Microsoft Office Access数据库引擎无法打开或写入该文件。它已由其他用户独占打开,或者您需要获得查看和写入其数据的权限

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



如果你仔细阅读了错误信息,你就会明白问题不在你的代码中。

你可以找到可能的问题原因,你可以推断出要采取的行动,我们可以'为你做这些。


If you read carefully the error message, you will understand that the problem is not in your code.
You are given the possible causes of problem, you can deduce actions to take, and we can't do them for you.


这篇关于Microsoft Office访问数据库引擎无法打开或写入该文件。该文件已由其他用户独占打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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