通过ODBC连接将记录插入Oracle数据库时的运行时错误“3146”

时间:2010-08-23 00:23:02

标签: oracle odbc ms-access-2007

我正在处理我的第一个Access应用程序,当我尝试将Access数据库中的记录插入Oracle数据库时,我遇到了麻烦。

插入第一条记录时没有错误,但第二条记录引发了“运行时错误'3146'”错误消息。

有什么想法吗?

Private Sub Command42_Click()


    Dim dbMyDatabase As DAO.Database
    Dim rsMyRecords As DAO.Recordset

    Dim qdMyParameters As DAO.QueryDef

    Dim qODBC           As DAO.QueryDef
    Dim sql             As String
    Dim sqODBC          As String
    Dim sConnectDAO     As String
    Dim sVariable       As String
    Dim qdfTimeTrack    As DAO.QueryDef
    Dim qdfLocal        As DAO.QueryDef

    Dim sWorkDate   As String
    Dim sHours      As String
    Dim sCreateDate As String
    Dim sCreateUserId As String
    Dim sWmDbId     As String
    Dim sCsubDbId   As String
    Dim sComments   As String

    Set dbMyDatabase = CurrentDb

    Set qdfTimeTrack = CurrentDb.QueryDefs("QADB-INSERT")
    sConnectDAO = "ODBC;DSN=QADB;DBQ=QADB ;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;"
    qdfTimeTrack.Connect = sConnectDAO
    qdfTimeTrack.sql = "set role all;"

    qdfTimeTrack.Execute

    Set qdfLocal = dbMyDatabase.QueryDefs("UpdateLocal")

    Set qdMyParameters = dbMyDatabase.QueryDefs("TimeRecordsForExport")

    Set rsMyRecords = qdMyParameters.OpenRecordset()

    Do While Not rsMyRecords.EOF

        sql = "INSERT INTO DAILY_JOB_ACTIVITIES ( DB_ID, PER_PER_DB_ID, CNUM_DB_ID, WORK_DATE, HOURS, CREATE_DATE, CREATE_USER_ID, WM_DB_ID, CSUB_DB_ID, COMMENTS ) " + _
            " values " + _
            " ( " + _
            " NIMS.DJA_SQ.NEXTVAL " + _
            " , 600178038 " + _
            " , '" & rsMyRecords(2).Value & "'" + _
            " , nvl(to_date('" & rsMyRecords(3).Value & "', 'MM/DD/RRRR HH12:MI:SS PM'), SYSDATE)" + _
            " , '" & rsMyRecords(4).Value & "'" + _
            " , nvl(to_date('" & rsMyRecords(5).Value & "', 'MM/DD/RRRR HH12:MI:SS PM'), SYSDATE)" + _
            " , '" & rsMyRecords(6).Value & "'" + _
            " , '" & rsMyRecords(7).Value & "'" + _
            " , '" & rsMyRecords(8).Value & "'" + _
            " , '" & rsMyRecords(9).Value & "'" + _
            " ); "

        MsgBox sql

        qdfTimeTrack.sql = sql

        ' Update QADB
        qdfTimeTrack.Execute

        ' qdfLocal.sql = "update TimeTrack set EXPORTED_FLAG = '1' where DB_ID = " & rsMyRecords(0).Value
        ' qdfLocal.Execute

        rsMyRecords.MoveNext

    Loop

    MsgBox "Records exported.  Remember to update refresh the internal database!"

End Sub

P.S。

我意识到我还没有错误处理。一旦我理解了这样的东西在VBA中的作用,我就会添加它。如果您对此有任何意见,请同时发布。

1 个答案:

答案 0 :(得分:3)

我会执行以下调试:

  1. 取出执行insert
  2. 的Execute语句
  3. 捕获第一个和第二个插入语句
  4. 尝试在SQL客户端中运行这两个语句,并查看Oracle引发的错误。