我无法使用.net应用程序在Oracle表中插入超过5120条记录

时间:2018-01-17 11:50:07

标签: c# oracle insert sql-loader

我使用以下代码插入超过100 000条记录的批量

C#功能:

public void ExcelUpload(DataTable dt)
    {

    try
    {
        objBus.ClearMDPreprocessed();
        lblError1.Visible = true;
        lblError1.Text = "Preparing Sheet for Validations. Please Wait...";
        using (StreamWriter wr = new StreamWriter(MapPath(ConfigurationManager.AppSettings["MASTER_DATA_FOLDER"].ToString()) + "\\RawMasterData_PREPROCESSED.txt"))//(@"e:\WorkingFolder\output.txt"))
        {
            foreach (DataRow row in dt.Rows)
            {
                wr.WriteLine(row["EMPNO"] + "," + row["MODEL"] + "," + row["PRIMARY_SUPERVISOR"] + "," + row["PROJECT_MANAGER"] + "," + row["ISBPS"] + "," + row["BU"]);
            }
        }
        System.Diagnostics.Process sysprocess = new Process();
        string myCommand = @"/c SQLLDR " + ConfigurationManager.AppSettings["ORA_CONN_MASTER_" + ConfigurationManager.AppSettings["CONN"].ToString().Trim()].ToString().Trim() + " LOG=" + MapPath(ConfigurationManager.AppSettings["MASTER_DATA_FOLDER"].ToString()) + "\\MasterDataUpd_PP.Log" + " CONTROL=" + MapPath(ConfigurationManager.AppSettings["MASTER_DATA_FOLDER"].ToString()) + "\\Ctrl_PreProcessed_Raw.txt";
        ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe", myCommand);
        startInfo.RedirectStandardOutput = true;
        startInfo.UseShellExecute = false;
        startInfo.WorkingDirectory = MapPath(ConfigurationManager.AppSettings["MASTER_DATA_FOLDER"].ToString());
        startInfo.RedirectStandardError = true;
        startInfo.RedirectStandardInput = true;
        sysprocess = System.Diagnostics.Process.Start(startInfo);
        sysprocess.WaitForExit();
        if ((sysprocess.ExitCode == 4))
        {
            lblError1.Visible = true;
            lblError1.Text = "Sheet ready for Validations.Click on Validate";
            btnValidate.Visible = true;
            btnDirectUpload.Visible = true;

        }
        else
            HttpContext.Current.Response.Write("NOT DONE");
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

Ctrl_Preprocessed_Raw.txt内容:

LOAD DATA
    INFILE RawMasterData_PREPROCESSED.txt
    BADFILE dataFile.bad
    APPEND INTO TABLE MSI_MASTER_DATA_RAW
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    (EMPNO,MODEL,PRIMARY_SUPERVISOR,PROJECT_MANAGER,ISBPS,BU)

2 个答案:

答案 0 :(得分:1)

我不知道C#,但LOAD DATA INFILE ...看起来非常像SQL * Loader一样。它有一个控制文件。在其中,您可以设置错误限制,一旦达到该限制就终止执行。所以,也许它设置为5120.也许你可以检查一下。

[编辑]

Gosh,当然它没有设置为5120 ...你设法加载那么多行。默认情况下,限制设置为50.如果查看SQL * Loader日志文件(以及BAD文件,如果将它们设置为使用 - 是的,您应该设置它),您可能会找到这些信息在那里。

答案 1 :(得分:1)

我已使用以下步骤解决了这个问题:

1)startInfo.RedirectStandardOutput = false; //我这是假的

2)startInfo.RedirectStandardInput = true; //我已评论过这一行。

这解决了我的问题,我能够通过SQL loader在oracle中插入批量记录,而不会出现上述代码的任何问题。感谢大家的投入。 :)