在Visual Studio代码中将“ Microsoft.Jet.OLEDB.4.0”提供程序的目标设置为x86并未在本地计算机上注册错误

问题描述

我是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中使用连接生成器?因此,在设置下,使用以下命令:

enter image description here

当您单击上面的[...]连接生成器时?你得到这个:

您可以通过选择以下选项来选择JET: enter image description here

单击高级后,您就有机会选择喷气机或ACE。由于这是一个较旧的mdb文件,因此无需使用ACE。

因此,在高级上,您可以选择:

enter image description here

因此,在上面,您可以(并且应该)选择喷气式飞机。

现在,一旦完成以上所有操作? 当然您不会猜测, 当然,您没有运行代码, 当然,您花费了那巨大的5秒钟,然后单击“测试连接”按钮,对吗?

这个:

enter image description here

那么,您已经使用了测试连接,对吗?还是您如何测试此连接?

好,接下来: 将项目强制为x86。好吧,从Visual Studio启动时,“任何cpu”默认情况下都将以x32位运行(因为Visual Studio是x32位程序)。但是,是否从Windows命令提示符启动.exe?然后,您将获得一个x64位的进程内程序,并且无法使用JET。

所以,是的,您应该将项目强制为x86

来自VS的

enter image description here

然后从中选择新内容:

enter image description here

然后这: enter image description here

现在,您有两个选择-“ any cpu”和x86。您肯定必须将这个项目强制为x86。

您现在在这里有选择

enter image description here

现在,如果mdb文件是2003年访问之后,那么您可能要选择ACE,但是再次使用连接生成器花费15秒并单击测试按钮将很快帮助您确定jet是否可以打开+使用文件。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...