开发者

VB.Net: DAO Object won't create DBEngine

I'm using a dynamically created Access database as a temporary storage for a file being inputed. I know that everything works, as on my dev machine I can get this code to run. But on another system (Win 7) it's not working. I'm being stopped at this line...

DAOEngine = New DAO.DBEngine

When it gets here, it just throws an error...

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

I have searched for the error, and I can't make sense of what it's telling me other then I'm using an old way of creating databases. And right now, I was hoping for a quick fix rather then rewriting the way my storage is working.

Again, I know my code is correct because my Dev machine compiles and runs this code just fine. I'll post the entire method in case there's something else I'm missing.

    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
            开发者_Go百科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


Are you using Microsoft DAO 3.6? Using 'Microsoft DAO 2.5/3.51 Compatibility Library' is very old. DAO 3.5 is the version which comes with Access 97.

Later I should've done a search on the GUID in the error message. Yes, that GUID is for DAO 3.5 which is very old and comes with Access 97 and Visual Basic 6. Use DAO 3.6/Jet 4.0 which comes with Weindows 2000 and newer OSs.

From PRB: CLSID {00000010-0000-0010-8000-00AA006D2EA4} Not Found When You Run an Application "The {00000010-0000-0010-8000-00AA006D2EA4} CLSID is associated with DAO350.dll."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜