VB.NET使用Windows默认的ODBC Jet驱动程序连接到MDB文件

发布于 2025-01-30 18:25:37 字数 1449 浏览 3 评论 0 原文

我正在使用VB.NET 6.0.5,Visual Basic和Visual Studio Community 2022构建Windows Winforms桌面应用程序。

我曾经使用 Microsoft Access数据库引擎连接到ACCDB文件。

它在开发机中运行良好,但是当我尝试部署到Windows 10 X64机器的新安装时;我必须让设置下载并安装ACE引擎。

我想尽可能减少先决条件,因为最终用户已经必须下载并安装.NET 6运行时。

我发现所有版本的Windows默认情况下都带有 Microsoft Access驱动程序(*.MDB),我想使用它。

驱动程序位置的新鲜副本为: c:\ Windows \ syswow64 \ odbcad32.exe </

code < /code 我认为,如果有人安装了办公室> jet.oledb 版本。

因此,我的问题是:

如何检查当前 jet.oledb 驱动程序版本,连接字符串是什么?

我当前的连接字符串是:

Dim cStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;User ID=Admin;Password=123;"

但是,它仍然给出 Microsoft.jet.oledb.4.0提供商未注册

我知道Ace Engine和ACCDB工作得更好,但使用JET和MDB就足够了。

请帮忙!

谢谢

更新:20/5/2022

我尝试过但没有成功的事情:

  • 我编制了目标 x86 < /strong>在许多参考文献中所说的 jet.oledb 不支持 x64
  • 我尝试了提供者= Microsoft.jet.oledb.10.0

I am building a Windows Winforms Desktop Application using VB.NET 6.0.5, Visual Basic, and Visual Studio Community 2022.

I used to connect to ACCDB File using Microsoft Access Database Engine.

It's working well in the development machine, but when I try to deploy to a fresh installation of a Windows 10 x64 machine; I have to let the setup download and install the ACE engine.

I want to reduce the prerequisites as much as possible, as the end-users already have to download and install the .NET 6 Runtime.

I found out that all versions of Windows come by default with Microsoft Access Driver (*.mdb) and I want to use that.

Drivers in Fresh copy of Windows 10 x64

The driver location is: C:\Windows\SysWOW64\odbcad32.exe

I think if someone installed Office it might update the driver to a different Jet.OLEDB version.

So my question is:

How to check the current Jet.OLEDB driver's version and what would be the connection string?

My current connection string is:

Dim cStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;User ID=Admin;Password=123;"

But still, it's giving that Microsoft.Jet.OLEDB.4.0 Provider is not registered.

Driver not registred

I know that ACE Engine and ACCDB work better but it's enough for me to use JET and MDB.

Please help!

Thank you

Update: 20/5/2022

Things that I tried but with no success:

  • I compiled the application to target x86 as it's said in many references that Jet.OLEDB doesn't support x64.
  • I tried Provider=Microsoft.Jet.OLEDB.10.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城挽邺 2025-02-06 18:25:37

好吧,如果您想知道连接字符串应该是什么?
让VS为您建立。

(您不想手工代码,也不想在连接字符串中输入 - 也无需)。

因此,在为您的VS项目设置时,然后在此处:

但是,您的问题/问题是现在VS2022是X64位(第一个版本是这样)。

我正在运行2019年,因此它仍将测试和验证X32位连接。我怀疑VS2022不会通过“测试”按钮,但是您仍然可以使用它来构建连锁顿​​。

因此,在上面,我们启动连接向导, - 访问默认的SQL Server的更改,我们现在有选择:

“在此处输入图像说明”

好吧,我们选择了访问权限,但是关于jet vs vs vs vs vs ace。

好吧,单击高级 - 此:

此:

因此,您可以选择喷气机或ACE。

选择喷气机,然后我们现在回到这里:

”在此处输入图像描述

现在,因为我正在运行VS2019,所以我的测试连接将起作用!!! - 对您来说,可能不会。因此,为您提供了测试连接按钮 - 您可以尝试一下,但是即使它给出了失败消息,您的连接仍然可以。

以下:

alt

好的,此时,我们已经完成了。

现在,我们在代码中可以使用代码中的上述连接。这样说:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Using conn As New OleDbConnection(My.Settings.TestJET)
        Using cmdSQL As New OleDbCommand("SELECT * FROM tblHotels", conn)

            conn.Open()
            Dim rstData As New DataTable
            rstData.Load(cmdSQL.ExecuteReader)

            Dim strMSG As String =
                "There are " & rstData.Rows.Count & " Hotels in the database " & vbCrLf &
                "The first Hotel is " & rstData.Rows(0).Item("HotelName")

            MsgBox(strMSG, MsgBoxStyle.Information, "Table info")

        End Using
    End Using

End Sub

我们明白了:

”“在此处输入图像描述”

现在,我想我可以查看连接字符串 - 但是我从来没有真正这样做 - 我总是让系统为我构建。

我明白了:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\Rides_be.mdb

正如您指出的那样,请确保您的项目设置为X32。但是,由于您运行VS2022,因此连接构建器应该可以使用,但是您必须运行项目以测试该连接,我认为在VS2022中不认为您可以使用“测试”连接。

另一方面,由于大多数办公室(甚至Acce Ace都是X64位?)。然后,如果您使用X64位ACE构建连接,则您的测试连接按钮应起作用。

Well, if you wondering what the connection string should be?
Let VS build it for you.

(you don't want to hand code, or type in connection strings anyway - and you don't have to).

So, in setting for your VS project, then here:

enter image description here

So, let click on that [...] and build the connection using JET (as opposed to ACE).

However, your issue/problem is that NOW vs2022 is x64 bits (first version to be that way).

I'm running 2019, so it will STILL test and VERIFY a x32 bit connection. I suspect that vs2022 WILL NOT pass the "test" button, but you STILL can use it to build the conneciton.

So, in above, we start the connection wizard, - hit change for the defaulted sql server, and we now have this choice:

enter image description here

Ok, we selected Access, but what about JET vs ACE.

Well, click on advanced - this:

enter image description here

And now we can (get to) choose the provider.

this:

enter image description here

So, you can choose jet or ACE.

choosing jet, then we now back to here:

enter image description here

Now BECAUSE I am running vs2019, then my test connection WILL work!!! - for you, it probably will not. So, the test connection button for you - you can try it, but EVEN if it gives a fail message, your connection is still ok.

This:

enter image description here

Ok, at this point, we are done.

We now in code can use the above connection in our code. Say like this:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Using conn As New OleDbConnection(My.Settings.TestJET)
        Using cmdSQL As New OleDbCommand("SELECT * FROM tblHotels", conn)

            conn.Open()
            Dim rstData As New DataTable
            rstData.Load(cmdSQL.ExecuteReader)

            Dim strMSG As String =
                "There are " & rstData.Rows.Count & " Hotels in the database " & vbCrLf &
                "The first Hotel is " & rstData.Rows(0).Item("HotelName")

            MsgBox(strMSG, MsgBoxStyle.Information, "Table info")

        End Using
    End Using

End Sub

And we get this:

enter image description here

Now, I suppose I could look at the connection string - but I never really do that - I always let the system build that for me.

I get this:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\Rides_be.mdb

As you noted, MAKE sure your project is set to x32. However, since you running vs2022, then the connection builder should work, but you HAVE to run your project to test that connection, I don't think in vs2022, you can use "test" connection.

On the other hand, since most of office (and even Access ACE is x64 bits?). Then if you build a connection using x64 bit ACE, then your test connection button should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文