我正在尝试使用oledb连接,同时使用csc.exe编译器。但不知何故,代码不会在.net ide上出错,但在csc.exe上会出错。
using System;
using System.Data.OleDb;
class vtBaglanti
{
static void Main()
{
string kaynak = "Provider=Microsoft.ACE.Oledb.12.0;Data Source=okul.accdb";
OleDbConnection baglanti = new OleDbConnection(kaynak);
baglanti.Open();
Console.WriteLine("VT Bağlantısı Sağlanmıştır.");
}
}
错误:
İşlenmeyenÖzelDurum:System.InvalidOperationException: 'Microsoft.ACE.Oledb.12.0'ağlayıcısıyerelmakinekayıtlıdeğil。
konum: System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionSt ring constr,DataSourceWrapper& datasrcWrapper)konum: System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection连接)konum: System.Data.OleDb.OleDbConnectionFactory.CreateConnection(的DbConnection 选项选项,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbCo nnectionPool池,DbConnection 拥有对象)konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection (DbConnection owningConnection,DbConnectionPoolGroup poolGroup, DbConnectionOpt离子userOptions)konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnec ing owningConnection,TaskCompletionSource1 retry, DbConnectionOptions userOpt ions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInterna l(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompl etionSource
1次重试,DbConnectionOptions userOptions)
konum: System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DBCONNECT ion outerConnection,DbConnectionFactory connectionFactory)konum: System.Data.OleDb.OleDbConnection.Open()konum:vtBaglanti.Main()
答案 0 :(得分:0)
错误意味着“Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册。之前已经讨论过了。您需要在计算机上安装ACE组件。您需要将ACE的CPU体系结构与已安装的MS Office版本的CPU体系结构相匹配。
此answer包含ACE发行版列表供您选择。
在大多数情况下,ACE的2010版本应该足够了:
Microsoft Access Database Engine 2010 Redistributable
PS。欢迎来到StackOverflow,请查看Tour以开始询问,回答,投票等等。