OLEDB 使用 32 位而不是 64 位 [英] OLEDB using 32bit instead of 64bit

查看:86
本文介绍了OLEDB 使用 32 位而不是 64 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 Excel 工作表导入一些数据,但 OleDbConnection 使用的是 32 位版本,因此无法找到提供者.我已经使用 64 位向导导入了,一切正常.

I need to import some datafrom a Excel worksheet but the OleDbConnection is using the 32bit version, so it cant find the provider. I already imported using the 64bit wizzard and everything is working fine.

已尝试使用以下连接字符串:

Already tried using the following connection string:

Provider=Microsoft.ACE.OLEDB.12.0;

  Public Shared Function ExcelToSqlServer() As Integer

        Dim ds As New DataSet
        Dim da As New OleDbDataAdapter

        Dim conn As New OleDbConnection



        Dim cnn As New SqlConnection
        Dim sqlBC As SqlBulkCopy

        Dim myFileDialog As New System.Windows.Forms.OpenFileDialog
        Dim xSheet As String = ""

        With myFileDialog
            .Filter = "Excel Files |*.xlsx"
            .Title = "Open File"
            .ShowDialog()
        End With

        If myFileDialog.FileName.ToString <> "" Then
            Dim ExcelFile As String = myFileDialog.FileName.ToString
            xSheet = "Incidentes"

            conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "data source=" & ExcelFile & "; " & "Extended Properties='Excel 12.0 Xml;HDR=Yes'")

            Try
                conn.Open()
                da = New OleDbDataAdapter("SELECT * FROM  [" & xSheet & "$]", conn)
                ds = New DataSet
                da.Fill(ds)

                sqlBC = New SqlBulkCopy(cnn)
                sqlBC.DestinationTableName = "Incidentes"
                sqlBC.WriteToServer(ds.Tables(0))
                conn.Close()
                Return 1
            Catch ex As Exception
                MsgBox("Error: " + ex.ToString, MsgBoxStyle.Information, "Informacion")
                conn.Close()
                Return -1
            End Try
        End If
        Return -1
    End Function

运行此函数时出现以下错误

I get the following error when I run this function

推荐答案

您的应用是否尝试使用 32 位或 64 位版本的 ACE OLE DB 提供程序取决于您的应用是否在 32 位版本中运行位或 64 位进程.32 位应用程序不能使用 64 位 OLE DB 提供程序,反之亦然.您的应用是在 32 位还是 64 位进程中运行取决于项目属性中的目标平台及其运行的操作系统.

Whether your app tries to use the 32-bit or 64-bit version of the ACE OLE DB provider is determined by whether your app is running in a 32-bit or 64-bit process. A 32-bit app can't use the 64-bit OLE DB provider and vice versa. Whether your app runs in a 32-bit or 64-bit process depends on the Target Platform in the project properties and the OS it runs on.

如果目标平台x86,那么该应用程序将仅在 32 位进程中运行,这意味着它不会在不支持的操作系统上运行32 位进程.

If the Target Platform is x86 then the app will only run in a 32-bit process, which means that it will not run on an OS that does not support 32-bit processes.

如果目标平台x64,那么该应用程序将仅在 64 位进程中运行,这意味着它不会在不支持 64 位进程的操作系统上运行.

If the Target Platform is x64 then the app will only run in a 64-bit process, which means that it will not run on an OS that does not support 64-bit processes.

如果目标平台Any CPU并且Prefer 32-bit框被选中,那么应用程序将在32位支持它的操作系统上的进程,否则在 64 位进程中.

If the Target Platform is Any CPU and the Prefer 32-bit box is checked then the app will run in a 32-bit process on an OS that supports it and in a 64-bit process otherwise.

如果目标平台Any CPU并且未选中Prefer 32-bit框,那么应用程序将在 64-位进程在支持它的操作系统上,否则在 32 位进程中.

If the Target Platform is Any CPU and the Prefer 32-bit box is not checked then the app will run in a 64-bit process on an OS that supports it and in a 32-bit process otherwise.

使用 ACE 有点棘手,因为如果您想支持所有可能的场景,您必须至少以两种不同的方式构建您的项目.问题是绝大多数已经安装了 Office 的人都会安装 32 位版本,这意味着他们将安装 32 位 ACE.要支持这些用户,您需要定位 x86 或定位 Any CPU 并选中 Prefer 32-bit.但是,如果您这样做,您将无法支持已安装 64 位 Office 或独立 64 位 ACE 的用户,因此您需要为他们进行第二次构建.您需要准确确定您的用户可能需要哪些组合,并确保您的构建版本能够支持他们.

Using ACE is slightly tricky because, if you want to support every possible scenario, you have to build your project at least two different ways. The problem is that the vast majority of people who have Office already installed will have installed the 32-bit version, which means that they will have 32-bit ACE installed. To support those users, you need to target x86 or else target Any CPU and check Prefer 32-bit. If you do that though, you won't be able to support users who have installed 64-bit Office or standalone 64-bit ACE, so you'd need a second build for them. You need to determine exactly what combinations your users might require and make sure that you have a build that will support them.

在您描述的特定情况下,x64目标平台任何 CPU目标平台> 并取消选中 Prefer 32-bit 应该可以解决问题,但这对 64 位 Windows 上的绝大多数 Office 用户不起作用.

In the specific case you describe, a Target Platform of x64 or else a Target Platform of Any CPU and unchecking Prefer 32-bit should do the trick, but that will not work for the vast majority of Office users on 64-bit Windows.

这篇关于OLEDB 使用 32 位而不是 64 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆