在 Visual studio 代码中将目标设置为 x86 'Microsoft.Jet.OLEDB.4.0' 提供程序未在本地机器上注册错误
Setting target to x86 in Visual studio code for 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine error
我是 C# 的新手,只需要使用它,因为我想读取一个非常古老的 MS Access 95 数据库文件。
当我尝试读取 mdb 文件时出现 The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
错误。我通读了一些线程并知道,这可能是因为我的 OS 是 64 位而驱动程序是 32 位。我也安装了更新的驱动,应该是支持32位和64位系统的,但是不知道安装后应该做什么。
到目前为止,这是我的代码:
using System.Data.OleDb;
namespace Access_DB
{
class Program
{
public static void Main(string[] args)
{
//Console.WriteLine("\nWhat is your name? ");
ReadData("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\but\Desktop\Access-DB\Test\access" , "select * from summary_0199_550");
}
public static void ReadData(string connectionString, string queryString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
}
}``
I also read that I should force the application to run on 32 bit by setting the target to x86 in project properties, but I cannot find such an option in visual studio code. How do I change the target here?
嗯,鉴于这是一个 mdb 文件?然后使用 JET 而不是较新的 ACE。原因有很多,但一个很好的原因是自 windows 98 年以来每台计算机上都安装了 JET。因此您不必安装任何东西。
接下来,为什么不使用 VS 中的连接生成器?所以,在设置下,使用这个:
当您单击上面的 [...] 连接生成器时?你得到这个:
您可以通过选择以下选项来选择 JET:
当你点击高级时,你有机会选择jet或ACE。由于这是一个较旧的 mdb 文件,因此无需费心使用 ACE。
因此,在高级版中,您可以选择:
因此,在上面,您可以(并且应该)选择喷气机。
现在,完成以上所有操作了吗?
你肯定猜不到,
你肯定不是 运行ning 代码,
您肯定花了 5 秒钟,然后点击了“测试连接”按钮,对吧?
这个:
所以,你用过测试连接,对吧?或者您是如何测试此连接的?
好的,接下来:
强制您的项目为 x86。好吧,当从 Visual Studio 启动时,“任何 cpu” 将默认 运行 作为 x32 位(因为 Visual Studio 是一个 x32 位程序)。但是,如果您从 windows 命令提示符启动 .exe 呢?然后你得到一个 x64 位 in-process 程序,你不能使用 JET。
所以,是的,你应该强制你的项目为 x86
来自VS:
然后从中选择新的:
然后是这个:
现在您有两个选择 - “任何 cpu”和 x86。你肯定想强制这个项目到 x86。
您现在可以在此处选择
现在,如果 mdb 文件是在 access 2003 之后,那么您可能想要选择 ACE,但是话又说回来,花 15 秒使用连接生成器并点击测试按钮将相当快速地帮助您确定 jet 是否可以打开 +使用文件。
我是 C# 的新手,只需要使用它,因为我想读取一个非常古老的 MS Access 95 数据库文件。
当我尝试读取 mdb 文件时出现 The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
错误。我通读了一些线程并知道,这可能是因为我的 OS 是 64 位而驱动程序是 32 位。我也安装了更新的驱动,应该是支持32位和64位系统的,但是不知道安装后应该做什么。
到目前为止,这是我的代码:
using System.Data.OleDb;
namespace Access_DB
{
class Program
{
public static void Main(string[] args)
{
//Console.WriteLine("\nWhat is your name? ");
ReadData("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\but\Desktop\Access-DB\Test\access" , "select * from summary_0199_550");
}
public static void ReadData(string connectionString, string queryString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
}
}``
I also read that I should force the application to run on 32 bit by setting the target to x86 in project properties, but I cannot find such an option in visual studio code. How do I change the target here?
嗯,鉴于这是一个 mdb 文件?然后使用 JET 而不是较新的 ACE。原因有很多,但一个很好的原因是自 windows 98 年以来每台计算机上都安装了 JET。因此您不必安装任何东西。
接下来,为什么不使用 VS 中的连接生成器?所以,在设置下,使用这个:
当您单击上面的 [...] 连接生成器时?你得到这个:
您可以通过选择以下选项来选择 JET:
当你点击高级时,你有机会选择jet或ACE。由于这是一个较旧的 mdb 文件,因此无需费心使用 ACE。
因此,在高级版中,您可以选择:
因此,在上面,您可以(并且应该)选择喷气机。
现在,完成以上所有操作了吗? 你肯定猜不到, 你肯定不是 运行ning 代码, 您肯定花了 5 秒钟,然后点击了“测试连接”按钮,对吧?
这个:
所以,你用过测试连接,对吧?或者您是如何测试此连接的?
好的,接下来: 强制您的项目为 x86。好吧,当从 Visual Studio 启动时,“任何 cpu” 将默认 运行 作为 x32 位(因为 Visual Studio 是一个 x32 位程序)。但是,如果您从 windows 命令提示符启动 .exe 呢?然后你得到一个 x64 位 in-process 程序,你不能使用 JET。
所以,是的,你应该强制你的项目为 x86
来自VS:
然后从中选择新的:
然后是这个:
现在您有两个选择 - “任何 cpu”和 x86。你肯定想强制这个项目到 x86。
您现在可以在此处选择
现在,如果 mdb 文件是在 access 2003 之后,那么您可能想要选择 ACE,但是话又说回来,花 15 秒使用连接生成器并点击测试按钮将相当快速地帮助您确定 jet 是否可以打开 +使用文件。