我有这个简单的 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 位操作系统的应用程序
关于c# - 为什么我会收到此异常 : "he ' Microsoft. ACE.OLEDB.12。 0' provider is not registered on the local machine"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56062607/