“Microsoft.ACE.OLEDB.12.0未在本地计算机上注册” [英] "Microsoft.ACE.OLEDB.12.0 is not registered on local machine"

查看:137
本文介绍了“Microsoft.ACE.OLEDB.12.0未在本地计算机上注册”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在将excel 2013数据导入数据库。但它引发了以下异常

Microsoft.ACE.OLEDB.12.0未在本地计算机上注册



我在使用MS Office 2013,VS 2012,SQLSERVER 2008和操作系统是Windows8



这是我的代码..



Hi,

I''m importing excel 2013 data to database. but it is raising the following exception
"Microsoft.ACE.OLEDB.12.0 is not registered on local machine"

I''m using MS Office 2013, VS 2012, SQLSERVER 2008 and Operating System is Windows8

Here is my code..

string filePath = string.Empty;

          #region //Save file in Server..
          if (file.ContentLength > 0 && (Path.GetExtension(file.FileName) == ".xls" || Path.GetExtension(file.FileName) == ".xlsx" || Path.GetExtension(file.FileName) == ".xlsm"))
          {
              filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                            Path.GetFileName(file.FileName));
              if (System.IO.File.Exists(filePath))
              {
                  System.IO.File.Delete(filePath);
              }
              file.SaveAs(filePath);
              //file.SaveAs(filePath);
          }
          #endregion;

          #region//connecting to excel file
          if (filePath != null)
          {
              //System.Data.OleDb.OleDbConnection oconn = new System.Data.OleDb.OleDbConnection(/*Jet.OLEDB.4.0*/    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";");
              System.Data.OleDb.OleDbConnection oconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=YES\";");
              oconn.Open();

              try
              {
                  if (oconn.State == System.Data.ConnectionState.Closed)
                      oconn.Open();
              }
              catch (Exception ex)
              {
                  // MessageBox.Show(ex.Message);
              }

              dynamic myTableName = oconn.GetSchema("Tables").Rows[0]["TABLE_NAME"];
              OleDbCommand ocmd = new OleDbCommand("select * from [" + myTableName + "]", oconn);
              OleDbDataReader odr = ocmd.ExecuteReader();

              if (odr.HasRows)
              {
                  while (odr.Read())
                  {
                      //....
                  }
                }

               }

          }

推荐答案

尝试修复它,如下所述: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/f11b2df9-fd0a-4528-987f-f95dfdccee0a/ [ ^ ]
Try to fix it as is described here: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/f11b2df9-fd0a-4528-987f-f95dfdccee0a/[^]


我们需要做的就是在我们的安装AccessDatabaseEngine 系统然后就像魅力一样......
All we need to do is Install AccessDatabaseEngine in our system then it works like charm..


这篇关于“Microsoft.ACE.OLEDB.12.0未在本地计算机上注册”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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