public void NzLoadFile(List<string> fileNames)
{
string targetFile, targetTable;
foreach (var fileName in fileNames)
{
try
{
targetFile = ValidateFile(fileName);
if (targetFile == null)
continue;
targetTable = getTargetTable(targetFile);
//string arguments = "-maxErrors 100 -host fxodwnet2d.nam.nsroot.net -u qsdb_dev_admin -pw password -db qsdb_dev -outputDir \"" + outputLog + "\" -t \"" + targetTable + "\" -df \"" + @targetFile + "\" -datestyle YMD -y2Base 2000 -dateDelim \"\" -delim \",\"";
string arguments = "-maxErrors \"" + maxErrors + "\" -host \"" + host + "\" -u \"" + user + "\" -pw \"" + password + "\" -db \"" + database + "\" -outputDir \"" + outputDir + "\" -t \"" + targetTable + "\" -df \"" + @targetFile + "\" -datestyle YMD -y2Base 2000 -dateDelim \"\" -delim \",\"";//时间形式yyyymmdd
string arguments=string arguments = "-maxErrors 100 -host 11111.nam.nsroot.net -u dev_sys -pw password -db dev -t tablename -df \"" + targetFile + "\" -outputDir \"" + outputLog + "\" -datestyle YMD -dateDelim \"-\" -timeStyle 24HOUR -timeDelim \":\" -delim \",\" ";//时间形式yyymmdd hh:mm:ss
StartProcessNzLoad(processName, arguments);
}
catch (IOException ex)
{
ourLogger.Error (string.Format("Nzload file {0} errors. Message-{1}", fileName, ex.Message));
}
}
}
/// <summary>
/// start the nzload process to import data into Netezza
/// </summary>
private void StartProcessNzLoad(string processName, string arguments)
{
Process nzload = new Process();
//nzload.StartInfo = new ProcessStartInfo(@"C:\Program Files\IBM Netezza Tools\7.0.2.4\nzadmin\Bin\nzload.exe", str);
nzload.StartInfo = new ProcessStartInfo(processName, arguments);
nzload.StartInfo.UseShellExecute = false;
nzload.StartInfo.RedirectStandardInput = true;
nzload.StartInfo.RedirectStandardOutput = true;
nzload.StartInfo.CreateNoWindow = false;
nzload.Start();
while (!nzload.HasExited)
{
Thread.Sleep(50);
}
{
string targetFile, targetTable;
foreach (var fileName in fileNames)
{
try
{
targetFile = ValidateFile(fileName);
if (targetFile == null)
continue;
targetTable = getTargetTable(targetFile);
//string arguments = "-maxErrors 100 -host fxodwnet2d.nam.nsroot.net -u qsdb_dev_admin -pw password -db qsdb_dev -outputDir \"" + outputLog + "\" -t \"" + targetTable + "\" -df \"" + @targetFile + "\" -datestyle YMD -y2Base 2000 -dateDelim \"\" -delim \",\"";
string arguments = "-maxErrors \"" + maxErrors + "\" -host \"" + host + "\" -u \"" + user + "\" -pw \"" + password + "\" -db \"" + database + "\" -outputDir \"" + outputDir + "\" -t \"" + targetTable + "\" -df \"" + @targetFile + "\" -datestyle YMD -y2Base 2000 -dateDelim \"\" -delim \",\"";//时间形式yyyymmdd
string arguments=string arguments = "-maxErrors 100 -host 11111.nam.nsroot.net -u dev_sys -pw password -db dev -t tablename -df \"" + targetFile + "\" -outputDir \"" + outputLog + "\" -datestyle YMD -dateDelim \"-\" -timeStyle 24HOUR -timeDelim \":\" -delim \",\" ";//时间形式yyymmdd hh:mm:ss
StartProcessNzLoad(processName, arguments);
}
catch (IOException ex)
{
ourLogger.Error (string.Format("Nzload file {0} errors. Message-{1}", fileName, ex.Message));
}
}
}
/// <summary>
/// start the nzload process to import data into Netezza
/// </summary>
private void StartProcessNzLoad(string processName, string arguments)
{
Process nzload = new Process();
//nzload.StartInfo = new ProcessStartInfo(@"C:\Program Files\IBM Netezza Tools\7.0.2.4\nzadmin\Bin\nzload.exe", str);
nzload.StartInfo = new ProcessStartInfo(processName, arguments);
nzload.StartInfo.UseShellExecute = false;
nzload.StartInfo.RedirectStandardInput = true;
nzload.StartInfo.RedirectStandardOutput = true;
nzload.StartInfo.CreateNoWindow = false;
nzload.Start();
while (!nzload.HasExited)
{
Thread.Sleep(50);
}
}
参数参考:http://www-01.ibm.com/support/knowledgecenter/SSULQD_7.1.0/com.ibm.nz.load.doc/c_load_sample_nzload_usage.html