c# - 为什么我会收到此异常 : "he ' Microsoft. ACE.OLEDB.12。 0' provider is not registered on the local machine"?

标签 c# .net oledb oledbconnection oledbexception

我有这个简单的 C# 控制台应用程序:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImporterRidistribuzioni
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("ImporterRidistribuzioni START");

            string path = "C:\\WS\\RegoleInoltro\\TunnelPro-DistribuzioneTitolario.xlsx";

            ReadREgoleInoltroFrmExcelFile(path);

            Console.WriteLine("ImporterRidistribuzioni END");
        }


        public static void ReadREgoleInoltroFrmExcelFile(string filePath)
        {
            DataTable regoleInoltro;
            string oleDBConnectionString = GetOleDBConnectionString(filePath);

            using (OleDbConnection conn = new OleDbConnection(oleDBConnectionString))
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = conn;

                // Get all Sheets in Excel File
                DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                /// Prendo il nome del primo foglio
                DataRow dr = dtSheet.Rows[0];
                string sheetName = dr["TABLE_NAME"].ToString();

                //regoleInoltro = GetDataTablePerimetro(cmd, sheetName);
                cmd = null;
                conn.Close();
            }
            //return regoleInoltro;
        }
    }
}

我的问题是,当它尝试执行这一行时:

conn.Open();

我收到此异常:“'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册。

这里是详细信息:

-       $exception  {"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."} System.InvalidOperationException
+       Data    {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
        HResult -2146233079 int
        HelpLink    null    string
+       InnerException  null    System.Exception
        Message "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."   string
        Source  "System.Data"   string
        StackTrace  "   at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper)\r\n   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)\r\n   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)\r\n   at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)\r\n   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)\r\n   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\r\n   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n   at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)\r\n   at System.Data.OleDb.OleDbConnection.Open()\r\n   at ImporterRidistribuzioni.Program.ReadREgoleInoltroFrmExcelFile(String filePath) in C:\\WS\\ArxeiaProtocollo2016\\ImporterRidistribuzioni\\Program.cs:line 32\r\n   at ImporterRidistribuzioni.Program.Main(String[] args) in C:\\WS\\ArxeiaProtocollo2016\\ImporterRidistribuzioni\\Program.cs:line 19" string
+       TargetSite  {Void GetDataSource(System.Data.OleDb.OleDbConnectionString, System.Data.OleDb.DataSourceWrapper ByRef)}    System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}

我正在 Azure 云中开发 Windows Server 2012

我安装了这个工具的 64 位版本:https://www.microsoft.com/en-us/download/details.aspx?id=13255

此处建议:The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

但什么都没有改变。我仍然遇到同样的错误。

为什么?我错过了什么?我该如何尝试解决这个问题?

最佳答案

看来您已经安装了 64 位版本的 MS Access,正如您应该的那样,因为 Windows Server 2012 机器几乎肯定是 64 位的。但是,您的 Console App.is 构建为 32 位。 尝试构建针对 32 位和 64 位操作系统的应用程序

enter image description here

关于c# - 为什么我会收到此异常 : "he ' Microsoft. ACE.OLEDB.12。 0' provider is not registered on the local machine"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56062607/

相关文章:

c# - 什么是用于加载系统配置属性的 .net 层次结构

.net - OleDB 与 SQLClient 相比有何优缺点?

c# - 在 WinForms WebBrowser 中编辑 CSS

c# - 使用 MongoDB 更新内部列表

c# - 使用 LINQ 将列表转换为列表的列表

c# - 如何使用 GDI 为多行文本的某些部分添加下划线?

c# - 在静态方法中找不到 request.querystring

.net - 无法启动应用程序 "WcfTestClient.exe"

c# - ADO.NET 获取 OleDbSchemaTable

c# - 在参数化 OleDbCommand 中使用 DateTime 时出现异常