How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

huangapple go评论89阅读模式
英文:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

问题

我已经遇到这个错误大约一个月了,我尝试了网上找到的几乎所有解决方案,但还是没有运气!每次尝试在Visual Studio 2022中使用服务器资源管理器连接到我的Microsoft Access数据库时,都会引发此错误。由于我的计算机是MacBook Pro,而虚拟机是64位设备,我正在Parallels Windows 11虚拟机上开发。我已经非常接近放弃,只是为了尝试解决这个问题而购买一台新的Windows电脑,所以非常感谢您可能提供的任何帮助!

我已经尝试安装了所有的Microsoft Access数据库引擎可再发行版,但仍然收到此错误。我还尝试了更改目标平台,但仍然收到相同的错误。到目前为止,我看到的每个论坛或视频都提供了这两个解决方案,所以我不确定接下来该去哪里!

英文:

I have been encountering this error for about a month now and I've tried just about every solution I could find online but still I have no luck! When attempting to connect to my Microsoft Access Database in Visual Studio 2022 using the server explorer this error is thrown every single time. I'm developing on a Parallels Windows 11 Virtual Machine due to the fact my computer is a MacBook Pro, and the VM is a 64 bit device. I'm very close to giving up all together and just buying a new Windows Computer just to try and get around this problem, so any help you may have will be greatly appreciated!

I've already attempted to install all the Microsoft Access Database Engine Redistributable's but I still receive this error. I have also attempted to change the target platform but still I keep receiving the same error. Every forum or video I've seen so far has given these 2 solutions so I'm not sure where to go from here!

答案1

得分: 2

以下是已翻译的内容:

首先,你是否强制将项目设置为x32位还是x64位?这个问题非常重要。虽然.NET代码可以作为任何CPU运行,但非托管的Windows代码不能,因此你的.NET项目必须与你安装的Access数据引擎的位数匹配。

请记住,使用VS2022会导致额外的问题。如果你使用x32(x86)版本的Access,那么你可以在VS2022中使用连接生成器,但测试连接按钮将无法工作,永远不会工作!

然而,如果你运行你的代码(假设强制使用x32位),那么代码应该可以运行,与Access数据引擎的连接应该正常工作。

因此,请记住,Visual Studio(VS)2022是第一个x64位版本的VS。这意味着可以使用向导和连接生成器,但并非在所有情况下都可以使用。更好的解决方案是安装x64位版本的Access数据引擎。

虽然你可以将项目设置为x32位,并构建这样的项目,甚至构建连接?

测试连接按钮将无法工作。而且,不管项目的位数设置如何,它都不会工作。(原因是连接生成器现在是x64位的,无法验证与x32位版本的Access的连接)。

当然,如果你安装了x64位版本的Access?那么是的,连接生成器和测试连接也会工作。

所以,就像8位Atari计算机无法运行16位代码一样?你也不能在那台8位Atari上运行16位代码?

嗯,自计算机问世以来,你也有同样的问题,因此你不能忽视这个混合x32位和x64位软件的问题。

所以,让我们假设你安装了Access数据引擎(x32位版本)。你不必安装MS-Access,甚至不必安装Access运行时。但你需要安装Access数据引擎。

因此,第一步,访问此链接:

Microsoft Access Database Engine 2016 可再发行版
https://www.microsoft.com/en-us/download/details.aspx?id=54920

从上面,最终你会有两个选择。
How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

所以,我们假设x32位版本。

所以,从VS2022开始,让我们构建并设置连接。

所以,从VS的项目属性、设置中,我们构建连接如下:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

非常注意上面:

我们没有使用测试连接按钮。它不会工作,因为我们使用的是Access x32,而VS是x64位的。

非常注意,我们点击了高级选项卡,并选择了ACE数据引擎,而不是JET数据引擎。不要跳过使用高级按钮的这一步。

所以,现在确保项目设置为x32位,如下所示:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

我们将假设使用x32(x86)位的Access。

如果你没有x32(x86)选项,那么添加一个新的配置,并确保将项目设置为x32位。

所以,正如我们所指出的,我们不能使用测试连接,但我们当然可以使用连接。你可以使用F5来运行,甚至在调试模式下运行。

因此,在一个窗体中,让我们添加一个按钮和一个网格视图。

按钮的代码如下:

private void button1_Click(object sender, EventArgs e)
{
    string strSQL
        = @"SELECT ID, FirstName, LastName, City, HotelName, Description
           FROM tblHotelsA ORDER BY HotelName";

    DataTable dt = new DataTable();

    using (OleDbConnection conn = new OleDbConnection(Properties.Settings.Default.AccessDB))
    {
        using (OleDbCommand cmd = new OleDbCommand(strSQL, conn))
        {
            conn.Open();
            dt.Load(cmd.ExecuteReader());
        }             
    }
    dataGridView1.DataSource = dt;
}

结果如下:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

英文:

Well, a few things.

First up, are you forcing the project to x32 bits, or x64 bits? This issue matters boatloads. While .net code can run as ANY CPU, un-managed windows code cannot, and your .net project thus has to match the bit size of the Access data engine you installed.

Keep in mind that use of vs2022 results in additional issues. If you using the x32 (x86) version of Access, then you can use the connection builder in vs2022, but the test connection button WILL not work, and will NEVER work!

However, when you run your code (assuming forced to x32 bits), then the code should run and the connection to the Access data engine should work fine.

So, keep in mind that Visual Studio (VS) for 2022 is the first version of VS that is x64 bits. This means that the wizards and connection builders can be used, but not in all cases. The better solution is to then install the x64 bit version of the Access data engine.

While you can set your project to x32 bits, and build such projects? And EVEN build the connection?

The test connection button will not work. And it will not work regardless of your bit size setting for the project. (The reason is the connection builder is x64 bits now, and it can't verify a connection to a x32 bit version of Access).

Of course, if you install the x64 bit version of Access? Then yes, both the connection builder AND ALSO the test connection will work.

So, just like an 8-bit Atari computer can't run 16-bit code? And you can't run 16-bit code on that 8-bit Atari?

Well, since the dawn of computers, YOU have the same issue, and thus you cannot ignore this issue of mixing x32 and x64 bit software.

So, let's assume you installed the Access data engine (x32 bit verison). You don't have to install MS-access, and you don't even have to install the Access runtime. However, you will need to install the Access data engine.

So, first step, this link:

Microsoft Access Database Engine 2016 Redistributable
https://www.microsoft.com/en-us/download/details.aspx?id=54920

From above, you will eventually wind up with 2 choices.
How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

So, we will assume x32 bit version.

So, from vs2022, let's build and setup the connection.

So, from vs in project properties, settings, we build the connection as follows:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

Note VERY close in above:

We did not use the test connection button. It will NOT work since we using access x32, and VS is x64 bits.

Note very close, we clicked on the advanced tab, and choose the ACE data engine, and NOT the JET data engine. Do NOT skip this step of using the Advanced button.

So, now make sure the project is set to x32 bits, here:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

We will assume access x32 (x86) bits.

If you don't have a x32 (x86) option, then add a new configuration, and make sure you set the project to x32 bits.

So, as noted, we can't use test connection, but we can certainly use that connection. And you can use f5 to run, even in debug mode.

So, in a form, lets drop in a button, and a grid view.

The button code is this:

    private void button1_Click(object sender, EventArgs e)
    {
        string strSQL
            = @"SELECT ID, FirstName, LastName, City, HotelName, Description
               FROM tblHotelsA ORDER BY HotelName";

        DataTable dt = new DataTable();

        using (OleDbConnection conn = new OleDbConnection(Properties.Settings.Default.AccessDB))
        {
            using (OleDbCommand cmd = new OleDbCommand(strSQL, conn))
            {
                conn.Open();
                dt.Load(cmd.ExecuteReader());
            }             
        }
        dataGridView1.DataSource = dt;
    }

And the result is now this:

How do I fix the error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine." In Visual Studio 2022

huangapple
  • 本文由 发表于 2023年8月4日 03:42:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76831193.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定