Microsoft Office访问数据库引擎无法打开或写入该文件。该文件已由其他用户独占打开

编程入门 行业动态 更新时间:2024-10-27 05:30:10
本文介绍了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访问数据库引擎无法打开或写入该文件。该文件已由其他用户独占打开

本文发布于:2023-10-20 09:12:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1510547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:该文件   其他用户   已由   无法打开   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!