アプリケーションにExcelファイルデータをアップロードしようとしています。私のローカルシステム(Windows 7)から、私のコードは正常に機能しています。しかし、サーバー(2003)でホストした後、ファイル(.xlsx)をアップロードしようとすると、エラーが発生します-System.InvalidOperationException:'Microsoft.ACE.OLEDB.12.0'プロバイダーがローカルマシンに登録されていません。
私のコード:
try
{
string connectionString = "";
if (fuUpload.HasFile)
{
string fileName = "_uploadTemp";
string fileExtension = Path.GetExtension(fuUpload.PostedFile.FileName);
string fileLocation = HttpContext.Current.Server.MapPath("~/FileUpload/" + fileName + fileExtension);
fuUpload.SaveAs(fileLocation);
lbl1.Text = "File Saved";
//Check whether file extension is xls or xslx
if (fileExtension == ".xls")
{
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (fileExtension == ".xlsx")
{
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
lbCon.Text = connectionString;
// Create OleDB Connection and OleDb Command
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
lbl2.Text = "Connection open";
//DataSet dtExcelSheetName=con.GetOleDbSchemaTable(OleDbDataAdapter.DefaultSourceTableName,null);
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
// dtExcelRecords = RemoveDuplicate(dtExcelRecords, "nOdc_Wwid");
con.Close();
lbl3.Text = "Connection Closed";
DataTable dttemp = new DataTable();
dttemp.Columns.Add("sOdc_People_Name", typeof(string));
dttemp.Columns.Add("vEmailId", typeof(string));
dttemp.Columns.Add("nOdc_Wwid", typeof(int));
dttemp.Columns.Add("Vpnaccess", typeof(string));//
dttemp.Columns.Add("Details", typeof(string));
for (int i = 0; i < dtExcelRecords.Rows.Count; i++)
{
dttemp.Rows.Add(dtExcelRecords.Rows[i][0].ToString(), dtExcelRecords.Rows[i][1].ToString(),
dtExcelRecords.Rows[i][2].ToString(), dtExcelRecords.Rows[i][3].ToString(), dtExcelRecords.Rows[i][4].ToString());
}
Session.Add("dtTemp", dttemp);//Created temp session to store the excel data
lbl4.Text = "Data added to temp table";
if (dttemp.Rows.Count <= 0)
{
gvMain.DataSource = mailutility.GetTempDataSetX("sOdc_People_Name", "vEmailId", "nOdc_Wwid", "Vpnaccess", "Details");
gvMain.DataBind();
gvMain.Rows[0].Visible = false;
}
else
{
gvMain.DataSource = dttemp;
gvMain.DataBind();
lnkConfirm.Visible = true;
lnkCancelC.Visible = true;
pnlLegend.Visible = true;
pnlLagendText.Visible = true;
mpX.Show();
lbl5.Text = "Grid binded";
foreach (GridViewRow gvr in gvMain.Rows)
{
CheckBox chkSelect = gvMain.Rows[gvr.RowIndex].Cells[0].FindControl("chkSelect") as CheckBox;
Label lblNameX = gvMain.Rows[gvr.RowIndex].Cells[1].FindControl("lblNameX") as Label;
Label lblEmailidX = gvMain.Rows[gvr.RowIndex].Cells[2].FindControl("lblEmailidX") as Label;
Label lblWwIdX = gvMain.Rows[gvr.RowIndex].Cells[3].FindControl("lblWwIdX") as Label;
if (lblNameX.Text != "" && IsValidEmail(lblEmailidX.Text) == true && ValidWWId(lblWwIdX.Text) == true)
{
chkSelect.Checked = true;
}
else
{
chkSelect.Checked = false;
chkSelect.Enabled = false;
gvr.BackColor = System.Drawing.Color.Yellow;
}
//Check for duplicate WWID
for (int i = 0; i < dttemp.Rows.Count; i++)
{
if (i != gvr.RowIndex)
{
if (dttemp.Rows[i]["nOdc_Wwid"].ToString() == lblWwIdX.Text)
{
chkSelect.Checked = false;
chkSelect.Enabled = false;
gvr.BackColor = System.Drawing.Color.Yellow;
}
}
}
}
}
}
}
catch (Exception es)
{
lbException.Text = es.ToString();
}
誰か助けてください。
Gulrej