从VB.NET调用Oracle过程仅适用于前两次

时间:2012-08-31 20:01:04

标签: vb.net oracle stored-procedures

我正在处理一个项目,该项目读入文件,为文件的每一行调用Oracle存储过程,根据过程返回的值重命名文件,然后将文件移动到服务器。我已经完成了所有这些工作,但由于某种原因,该过程只会在调用它的前两次返回一个值。在那之后,我什么也得不回来。我尝试在循环中关闭连接并重新打开它,但这没有用。我也非常不必这样做。

名称已更改,以保护无辜的服务器。

Do While Not endOfData
    Dim dataRecord As String = dataReader1.GetRecord
    If dataRecord = "End of Data" Then
        endOfData = True
    Else
        ' Read in record '
        indexRec = indexLoader.LoadPointerIndex(dataRecord, PointerIndexRecordType.Original)

        'Format date values '
        effdate = indexRec.EffDate.ToString("M/dd/yyyy")
        dir = "/" & easyFile & "/" & indexRec.EffDate.Year & "/" & indexRec.EffDate.Month & "/"


        'Connect to Oracle '
        Dim conn As New OracleConnection(connString)
        conn.Open()
        'Call proc with indexRec values '
        Dim myCMD As New OracleCommand()
        myCMD.Connection = conn
        myCMD.CommandText = "SCHEMA.PROC"
        myCMD.CommandType = CommandType.StoredProcedure
        'Setup Parameters '
        myCMD.Parameters.Add("P_CONTRACT_ID", OracleDbType.Varchar2, 10, Nothing, ParameterDirection.Input).Value = indexRec.Contract
        myCMD.Parameters.Add("P_EFFT_DATE", OracleDbType.Date, ParameterDirection.Input).Value = indexRec.EffDate
        myCMD.Parameters.Add("P_DIRECTORY", OracleDbType.Varchar2, 18, Nothing, ParameterDirection.Input).Value = dir
        myCMD.Parameters.Add("P_FILENAME_OUT", OracleDbType.Varchar2, 13, Nothing, ParameterDirection.Output)

        myCMD.ExecuteNonQuery()

        Result = CType(myCMD.Parameters("P_FILENAME_OUT").Value.ToString, String)
        myCMD.Dispose()
        conn.Close()
        conn.Dispose()

        'Rename PDF based on returned result '
        My.Computer.FileSystem.RenameFile(rootDirectory & "\" & configSettings.appFolder & "\" & indexRec.Contract & ".pdf", Result)

        'Verify that folder exists on server '
        sFolder = sDir & indexRec.EffDate.Year & "\" & indexRec.EffDate.Month
        If (Not Directory.Exists(sFolder)) Then
            Directory.CreateDirectory(sDir & indexRec.EffDate.Year & "\" & indexRec.EffDate.Month)
        End If

        'Move PDF to proper folder '
        My.Computer.FileSystem.CopyFile(rootDirectory & "\" & configSettings.appFolder & "\" & Result, sFolder & "\" & Result)
    End If
Loop

这是另一个团队管理的Proc。

create or replace
PROCEDURE PROC(P_CONTRACT_ID  IN VARCHAR2,
               P_EFFT_DATE    IN DATE,
               P_DIRECTORY    IN VARCHAR2,
               P_FILENAME_OUT OUT VARCHAR2)
--*****************************************************
    -- Name: PROC
    -- Purpose: Insert a contract statement                                       
    -- Authored by: 
    -- Created on: 
    -- Modifications:
    -- Seq Who Date Description
    -- ----------------------------------------------------
    -- 001 DAT 08/27/2012 Initial Release
    --*****************************************************
 AS

    V_CONTRACT_UID       NUMBER;
    V_CORRESPONDENCE_UID NUMBER;
    V_DEL_COUNT          NUMBER;
    V_NEW_FILE_URL       VARCHAR2(254);

BEGIN

    --Get the contract_uid
    SELECT CONTRACT_UID
       INTO V_CONTRACT_UID
       FROM ODS.CONTRACTS
       WHERE CONTRACT_ID = P_CONTRACT_ID;

    --If existing, delete the entry and add (dont do a merge).
    SELECT COUNT(CORRESPONDENCE_UID)
      INTO   V_DEL_COUNT
      FROM   CORRESPONDENCES
      WHERE  CONTRACT_UID = V_CONTRACT_UID
             AND TRUNC(CORRESPONDENCE_CREATION_DATE) = TRUNC(P_EFFT_DATE);

    IF V_DEL_COUNT > 0 THEN
      DELETE FROM CORRESPONDENCES
        WHERE  CORRESPONDENCE_UID IN
                  (SELECT CORRESPONDENCE_UID
                     FROM   CORRESPONDENCES
               WHERE  CONTRACT_UID = V_CONTRACT_UID
                 AND TRUNC(CORRESPONDENCE_CREATION_DATE) = TRUNC(P_EFFT_DATE));
    END IF;

    -- *** Create Correspondence Row and New File Name ***
    -- *** Create new file name ***
    V_CORRESPONDENCE_UID := CORRESPONDENCES_SEQ.NEXTVAL;
    P_FILENAME_OUT       := RTRIM(LTRIM(TO_CHAR(V_CORRESPONDENCE_UID) || '.pdf'));
    V_NEW_FILE_URL       := 'http://armstorage.integritycompanies.com' || P_DIRECTORY || P_FILENAME_OUT;

    INSERT INTO CORRESPONDENCES
        (CORRESPONDENCE_UID,
         CORRESPONDENCE_TYPE,
         CORRESPONDENCE_CREATION_DATE,
         CORRESPONDENCE_CONTENT_TYPE,
         CORRESPONDENCE_IMAGE_FILE_NAME,
         CORRESPONDENCE_IMAGE_FILE_EXT,
         CORRESPONDENCE_UPDATED,
         CORRESPONDENCE_URL,
         CORRESPONDENCE_DESC,
         CONTRACT_UID)
    VALUES
        (V_CORRESPONDENCE_UID,
         'ST',
         P_EFFT_DATE,
         'application/pdf',
         P_FILENAME_OUT,
         '.pdf',
         SYSDATE,
         V_NEW_FILE_URL,
         'Contract Statement',
         V_CONTRACT_UID);

    COMMIT;

EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE(SQLERRM);
        DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
        ROLLBACK;

END;

有任何建议或要求吗?

1 个答案:

答案 0 :(得分:0)

Proc正在寻找我传递的参数之一,并在另一个我无法访问的表上检查它的值。如果未找到该值,则返回“null”值。检查该问题的一些标准纠正了这个问题。