Компонент Microsoft office access database engine не может открыть или записать этот файл.он уже открыт исключительно другим пользователем
Мой код выглядит следующим образом
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