【问题标题】:VB.Net: DAO Object won't create DBEngineVB.Net:DAO 对象不会创建 DBEngine
【发布时间】:2010-10-08 16:39:21
【问题描述】:

我正在使用动态创建的 Access 数据库作为输入文件的临时存储。我知道一切正常,因为在我的开发机器上我可以让这段代码运行。但是在另一个系统(Win 7)上它不起作用。我被拦在了这条线上……

DAOEngine = New DAO.DBEngine

当它到达这里时,它只是抛出一个错误......

Creating an instance of the COM component with CLSID {00000010-0000-0010-8000-00AA006D2EA4} from the IClassFactory failed due to the following error: 80040112.

我已经搜索了错误,但我无法理解它告诉我的内容,然后我使用的是旧的创建数据库的方法。而现在,我希望快速修复而不是重写我的存储工作方式。

再次,我知道我的代码是正确的,因为我的开发机器可以很好地编译和运行这段代码。我会发布整个方法,以防我遗漏了其他东西。

    Private Sub ProcessFile(ByVal Exportname As String, ByVal ExportFile As String, ByVal ImportFile As String)
    ' Aperture variables
    Dim Table As Object 'OETable
    Dim Fields As Object 'OEFields

    ' DAO database variables
    Dim DAOEngine As DAO.DBEngine
    Dim rst As DAO.Recordset
    Dim ws As DAO.Workspace
    Dim db As DAO.Database
    Dim tbl As DAO.TableDef
    Dim fld As DAO.Field

    ' Integer vars
    Dim fieldcount As Integer
    Dim I As Integer
    Dim j As Integer
    ' Boolean Variables
    Dim CalcTotals As Boolean = False
    ' String Array Variables
    Dim headers() As String = Nothing
    ' String Variables
    Dim lvl_lookup As String
    Dim outputlist As String
    Dim throwaway As String = ""
    Dim totalstring As String
    ' Array vars
    Dim totals() As Object

    ' Use an access database to add the serial numbers
    'ws = DAODBEngine_definst.Workspaces(0)
    DAOEngine = New DAO.DBEngine
    ws = DAOEngine.Workspaces(0)
    If File.Exists(alAperture.prjPath & "\temp.mdb") Then
        File.Delete(alAperture.prjPath & "\temp.mdb")
    End If
    db = ws.CreateDatabase(alAperture.prjPath & "\temp.mdb", DAO.LanguageConstants.dbLangGeneral)
    tbl = db.CreateTableDef("legend")

    If alAperture.tbls.Item(Exportname & " Table") Is Nothing Then
        Table = alAperture.tbls.Item("Legend Text Table")
    Else
        Table = alAperture.tbls.Item(Exportname & " Table")
    End If

    Fields = Table.Fields
    fieldcount = Fields.Count
    ' Create the fields
    For I = 0 To fieldcount - 1
        If Fields.Item(I).DataType = 2 Then
            ' We have a numeric field
            fld = tbl.CreateField(Fields.Item(I).Name, 6)
            CalcTotals = True
        Else
            fld = tbl.CreateField(Fields.Item(I).Name, 10, 255)
            fld.AllowZeroLength = True
        End If
        tbl.Fields.Append(fld)
    Next
    ' Create the table
    db.TableDefs.Append(tbl)

    ' Open the table as a recordset
    rst = db.OpenRecordset("legend", DAO.RecordsetTypeEnum.dbOpenTable)
    ' Open the exportfile for read
    Dim streamIn As StreamReader = New StreamReader(ExportFile)
    ReDim totals(fieldcount - 1)

    I = 0
    lvl_lookup = ""

    Do
        ' Grab next record and redim to dimension of table, minus the series column
        Dim nextRecord() As String = Split(streamIn.ReadLine, """,""")
        ReDim Preserve nextRecord(fieldcount - 1)
        If I = 0 Then
            headers = nextRecord
            I = 1
        Else
            ' *** HEADER RECORD
            If lvl_lookup = "" Then
                lvl_lookup = nextRecord(0)
                ' Add the header record
                rst.AddNew()
                rst.Fields(0).Value = lvl_lookup
                rst.Fields(1).Value = 0
                For j = 2 To fieldcount - 1
                    If rst.Fields(j).Type = 10 Then
                        rst.Fields(j).Value = Replace(headers(j - 1), """", "")
                    Else
                        rst.Fields(j).Value = 0
                    End If
                Next
                rst.Update()
            End If
            ' *** RECORDS
            If nextRecord(0) = lvl_lookup Then
                ' addrecords
                addrecord(totals, nextRecord, rst, fieldcount, I)
            Else
                ' add total row
                ' padlines
                If CalcTotals Then
                    rst.AddNew()
                    rst.Fields(0).Value = lvl_lookup
                    rst.Fields(1).Value = I
                    totalstring = "Total:"
                    For j = 2 To fieldcount - 2
                        If rst.Fields(j).Type = 6 Then
                            If IsNothing(totals(j)) Then
                                rst.Fields(j).Value = 0
                            Else
                                rst.Fields(j).Value = totals(j)
                            End If
                        Else
                            rst.Fields(j).Value = totalstring
                            totalstring = ""
                        End If
                    Next
                    rst.Fields(9).Value = 0
                    rst.Update()
                    I = I + 1
                End If
                'padlines
                While I <= 80
                    rst.AddNew()
                    rst.Fields(0).Value = lvl_lookup
                    rst.Fields(1).Value = I
                    rst.Update()
                    I = I + 1
                End While
                I = 1
                lvl_lookup = nextRecord(0)
                ReDim totals(fieldcount - 2)
                ' add record
                addrecord(totals, nextRecord, rst, fieldcount, I)
            End If
            If streamIn.EndOfStream Then
                ' add total row
                ' padlines
                If CalcTotals Then
                    rst.AddNew()
                    rst.Fields(0).Value = lvl_lookup
                    rst.Fields(1).Value = I
                    totalstring = "Total:"
                    For j = 2 To fieldcount - 2
                        If rst.Fields(j).Type = 6 Then
                            If IsNothing(totals(j)) Then
                                rst.Fields(j).Value = 0
                            Else
                                rst.Fields(j).Value = totals(j)
                            End If
                        Else
                            rst.Fields(j).Value = totalstring
                            totalstring = ""
                        End If
                    Next
                    rst.Fields(9).Value = 0
                    rst.Update()
                    I = I + 1
                End If
                'padlines
                While I <= 80
                    rst.AddNew()
                    rst.Fields(0).Value = lvl_lookup
                    rst.Fields(1).Value = I
                    rst.Update()
                    I = I + 1
                End While
            End If
        End If
    Loop Until streamIn.EndOfStream
    streamIn.Close()
    ' ok lets write the import file

    Dim streamOut As StreamWriter = New StreamWriter(ImportFile)
    rst.MoveFirst()
    Do Until rst.EOF
        outputlist = Chr(34) & rst.Fields(0).Value & Chr(34) & "," & Chr(34) & VB6.Format(rst.Fields(1).Value, "00") & Chr(34)
        For j = 2 To fieldcount - 1
            outputlist = outputlist & "," & Chr(34) & rst.Fields(j).Value & Chr(34)
        Next
        streamOut.WriteLine(outputlist)
        rst.MoveNext()
    Loop
    streamOut.Close()
    rst.Close()
    db.Close()
    ws.Close()

    rst = Nothing
    db = Nothing
    ws = Nothing
    fld = Nothing
    tbl = Nothing
    Table = Nothing
    Fields = Nothing
End Sub

【问题讨论】:

    标签: vb.net windows-7 dao


    【解决方案1】:

    您使用的是 Microsoft DAO 3.6 吗?使用“Microsoft DAO 2.5/3.51 Compatibility Library”已经很老了。 DAO 3.5 是 Access 97 附带的版本。

    稍后我应该搜索错误消息中的 GUID。是的,该 GUID 用于非常旧的 DAO 3.5,它带有 Access 97 和 Visual Basic 6。使用带有 Wendows 2000 和更新的操作系统的 DAO 3.6/Jet 4.0。

    来自PRB: CLSID {00000010-0000-0010-8000-00AA006D2EA4} Not Found When You Run an Application“{00000010-0000-0010-8000-00AA006D2EA4} CLSID 与 DAO350.dll 相关联。”

    【讨论】:

    • +1。 DAO 3.6 是最新版本,它现在是 Windows 的一部分(正如 Tony 提醒我的那样),因此无需安装它。我认为如果你正在使用它,你将不得不安装 DAO 3.5(如果这也是错误的,欢迎更正)。 'Microsoft DAO 2.5/3.51 Compatibility Library' 被提供来帮助从 VB3 升级,确实很老了。
    • 如果您想使用 DAO 3.5 那么是的,您必须安装它。当然,鉴于 DAO 3.6 和 Jet 4.0 随 Windows 2000 和更新版本一起提供,你今天使用 3.5 是愚蠢的。
    • 是的,就是这样。我只是很困惑我的电脑安装了 3.5 版本而其他人没有。谢谢!
    • MarkJ,我们 Access 人员将兼容性库视为协助从 Access 2.0 升级。 严格来说DAO 3.6 并不是最新版本。 Access 组已经对源代码进行了分叉,并正在调用 ACE 并提供一些新功能。但大多数情况下与此讨论无关,因为如果可能的话,您应该坚持使用操作系统附带的内容以避免安装。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 2016-01-18
    相关资源
    最近更新 更多